Rediscovering the Obvious

…stumbling in the footsteps of greatness

Nullable value types… aka why do you have ? or ?? there?

without comments

I’ve had a bunch of people ask me recently what the ?? operator is in C#.

From what I’ve seen, the following two declarations have the same effect (other than the names):
        int? myInt = null;
        Nullable<int> myInt2 = null;

As are the following two:
        return myInt ?? 5;
        return myInt2.HasValue ? myInt2.Value : 5;

 

Written by erwilleke

August 10th, 2007 at 1:03 pm

Posted in Uncategorized

Leave a Reply