The C# 2.0 compiler also provides a handy shorthand operator for this - ?.
To define a nullable integer you use one of the following statements:
Nullable<int> nullInt = new Nullable<int>();
Nullable<int>nullInt = new Nullable<int>(2); // Initialzie to 2
OR
int? nullInt;
int? nullInt = 2;
Console.WriteLine(nullInt.HasValue ? nullInt.Value.ToString() : "NULL!");
Very handy!
0 comments:
Post a Comment