An Uncommon C# DooDad
Submitted by brian on Wed, 11/07/2007 - 2:05am.
So I came across this post about the uncommon features of C# when I thought I'd add one of my own that I recently learned from the master of HttpContext.Current.Items, none other than Mike Duncan.
It's the good 'ol coalesce operator (??). Yeah, yeah, you've heard of it in SQL and the like, but it's pretty hot in C#. It will return the first non-null item from a group of two or more objects. Here's an example noting the hottest card game ever made!
int? atat = null;
int cat = 1;
int rat = atat ?? 41 + cat;
And of course the outcome is the answer to life, the universe, and everything. Naturally.
Tags:
















