0

Is there any special expression or some kind or syntactic sugar built in in C# that would allow one to change a variable's value or leave it alone depending on condition? I mean something that would do following:

str = (condition) ? "modifiedString" : str;

or

if (condition) str = "modifiedString";

But with simplicity of null coalescing operator. Something like

str = (condition) ?? "modifiedString"
4

1 回答 1

2

怎么样

if(condition)
   str = "modified"

这不正是你想要的吗?

于 2013-06-27T05:39:36.677 回答