class MyClass {
public int MyInt { get; }
public int? MyNullableInt { get; } // This property can be null even though it's of type 'int'
public MyClass(int? input) { // input can be null
MyInt = input != null ? input.Value : 0; // .Value throws an exception when accessed if input is null
MyNullableInt = input;
}
}
// ..
static void Test() {
var mc = new MyClass(null);
if (mc.MyNullableInt == null) Console.WriteLine("Was null!");
}
Code snippet taken from "Complete C# Quick Reference - C# 2, 3 and 4".