#207 – Nullable Types
January 10, 2011 5 Comments
Because value types can’t normally represent null values, C# includes nullable types–types that can represent their normal range of values or represent a null value.
Any value type can be used as a nullable type by adding a trailing ? to the type name.
int i = 12; // regular int, can't be null int? j = 22; // Nullable int, can be null j = null; // Can also be null
Here are some other examples of nullable types. In each case, we can set the variable’s value to null, which means that the variable doesn’t have a value that falls within the range of the corresponding type.
double? r = null; bool? thisIsFalse = null; Mood? myMood = null;
Pingback: #566 – Implicit Conversions to Nullable Types « 2,000 Things You Should Know About C#
Pingback: #581 – Boxing and Unboxing Nullable Types « 2,000 Things You Should Know About C#
Pingback: #1,050 – Implicit Conversions between Nullable Types | 2,000 Things You Should Know About C#
Pingback: #1,060 – Explicit Conversions between Nullable Types | 2,000 Things You Should Know About C#
Hi
I hink is good to add info, that nullable type is not reference type, but strict. Well answered there: http://stackoverflow.com/a/3149180/328829