In C#, what is the default value of a class instance variable of type int??
For example, in the following code, what value will MyNullableInt
I felt important to share the Nullable method which is particularly handy when working with math computations that use Nullable aka int? values. There are many times when you don't have to check HasValue property and you can just use GetValueOrDefault() instead.
var defaultValueOfNullableInt = default(int?);
Console.WriteLine("defaultValueOfNullableInt == {0}", (defaultValueOfNullableInt == null) ? "null" : defaultValueOfNullableInt.ToString());
var defaultValueOfInt = default(int);
Console.WriteLine("defaultValueOfInt == {0}", defaultValueOfInt);
Console.WriteLine("defaultValueOfNullableInt.GetValueOrDefault == {0}", defaultValueOfNullableInt.GetValueOrDefault());