Checking for a value

Basic types / Nullable types

using System;

int? n1 = GetIntValue(false);
var exists1 = n1.HasValue;
//exists1 is True

int? n2 = GetIntValue(true);
var exists2= n2 != null;
//exists2 is False

Console.WriteLine("{0}, {1}", exists1, exists2);

int? GetIntValue(bool isNull) {
    return isNull ? null : 42;
}