Nullable Types
C#, C# Language March 10th, 2006In C# and .net you can define a variable of the standard values types to be nullable as well. This is extremely useful in circumstances when you want to check if a varaible has been intialized correctly.
For example, if you have a class that represents a user which has an integer user id and it is not initialized in the constructor. Rather than having the user id intitialize to 0 (zero) (which would be the default for an integer) as the User id 0 may well be a valid user’s id. the type can be defined as a nullable integer using int? UserID and will default to null instead.
Examples of nullable declarations
[csharp]
int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = ‘a’;
int?[] arr = new int?[10];
[/csharp]
Recent Comments