Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这就是我想做的:
string x = if(true) "String Val" else "No String Val";
那可能吗?
您所说的称为条件语句:
string x = boolVal ? "String Val" : "No String Val";
如果您真的希望字符串在 bool 为 false 时没有值,您可以更改为:
string x = boolVal ? "String Val" : null;
string x = condition ? trueValue : falseValue;
http://msdn.microsoft.com/en-us/library/ty67wk28.aspx