C# double question mark (??) syntax
10 Dec 2010, 15:28
Subscribe to Richies blog (RSS)
Thought I'd share something that I learned today about C#.
Been using it nearly 10 years, and didn't know about the ?? syntax!
a = b ?? c;
a will be assigned the value of b if b is not null. If b is null, a will be assigned the value of c.
i.e. its shorthand for:
if (b == null) a = c else a = b
Not earth shattering, but a nice time saver, and it follows the same theme of a question mark indicating the null option on system type declarations, like int?, date? etc..
Comments | 2 |
Ratings | 62 |
Average rating | 99% |
Posted | 10 Dec 2010, 15:28 |
View blog | Richies blog |
Previous blog entry:
Microsoft Access as a website database
Next blog entry:
SELECT COUNT(*) in LINQ