Not null or not null or...

icon3
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted July 4, 2007 at 22:13 (UTC)

Excuse me for publishing such a shot post (it's now the last one, so please don't feel too annoyed), but this little nice thing in C# can be nice to know:

1
2
3
string a = null;
string b = "hello";
string c = a ?? b; // c equals "hello"

In other words, it returns the first argument that is not null.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.