Negate the null-coalescing operator
Posted
by jhunter
on Stack Overflow
See other posts from Stack Overflow
or by jhunter
Published on 2010-05-17T21:17:26Z
Indexed on
2010/05/17
21:20 UTC
Read the original article
Hit count: 292
c#
|null-coalescing-operator
I have a bunch of strings I need to use .Trim() on, but they can be null. It would be much more concise if I could do something like:
string endString = startString !?? startString.Trim();
Basically return the part on the right if the part on the left is NOT null, otherwise just return the null value. I just ended up using the ternary operator, but is there anyway to use the null-coalescing operator for this purpose?
© Stack Overflow or respective owner