Blogger Jeff = new Blogger

Programming and stuff in Western PA

C# coalesce operator

Damn Microsoft! I finally thought I had my thick head wrapped around C# when they decide to come out with a boatload of new features to further confuse, err, I mean enhance things.

I was quite happy to read that they added a coalesce operator to C#. For those of you who use Sql Server on a regular basis, you’re probably quite familiar with this function. What it does is allow you to pass a list of values, and will return the first non-null value.

For instance, in previous versions of C# we might have code that looks like this :

After running this, the string “brian” gets outputted to the console. We can now rewrite this a little cleaner with the new coalesce (??) operator :

After running this, you’ll see we get the same results. Thanks again to the C# team for giving me the capability to make my code even more unreadable 😉

Tags: , ,


November 23, 2007 - Posted by | .Net, C#, Technology


  1. Ha, your right. Learning Ruby at the moment (wish me luck) and this all finally makes sense. I’d have to agree, its hard to understand the concept of what’s going on thanks to Microsoft’s new “feature.” I don’t think that even a //comment can fix that there buddy ;-).

    Comment by Julian | November 30, 2007 | Reply

  2. very interesting.
    i’m adding in RSS Reader

    Comment by music | January 8, 2008 | Reply

  3. Howdy! Someone in my Myspace group shared this website with us
    so I came to give it a look. I’m definitely loving the information. I’m
    book-marking and will be tweeting this to my followers!
    Great blog and great style and design.

    Comment by saffron extract | August 4, 2013 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: