Null Coalescing Operator

I didn’t know about this C# 2.0 operator (??) until ReSharper suggested it as a replacement for a particular use of arithmetic if (?:) that I’d added to some code recently.  I already prefer C# to VB.NET because of its terse syntax and stricter compiler, so this discovery tipped the scales just that much more.

The most recent blog post Google coughed up for this operator is this one, from Aaron Zupancic.  Aaron links to another post that demonstrate its use for viewstate.


  1. Dave says:

    LOL, this JUST happened to me too – with the same operator! I saw the ?? in use in a code sample for some of the .NET MVC stuff I was reading on scottgu’s blog this weekend.

    Man, I need to get Resharper I think. There needs to be a blog called “Language Features You Never Knew Existed” where someone could post up very, very short syntax or API items each day and a short code sample.

    Hmmm, maybe we should start that blog – that would be a great way to LEARN all of these. Or have readers submit them. 🙂

  2. Scott says:

    I like the blog idea a lot, particularly because it would add context to usage of these language features.

    ReSharper is awesome. I highly recommend grabbing the 30-day trial immediately. You could buy it immediately too (download it, get the backup CD). I think if you buy it now, you get a free upgrade to ReSharper 4.0 when it ships. It took maybe a day or two of my 30-day trial to decide that I would buy my own copy of ReSharper 3.x. Beyond its refactoring prowess, it has a great test runner, usage finder, and other search tools for zipping around your codebase.

    There’s a .NET user group here in Maryland that’s going to do a 90-minute intro on .NET MVC. I’m definitely looking forward to that.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.