Information Technology Reference
In-Depth Information
Assigning to a Nullable Type
There are three kinds of values you can assign to a variable of a nullable type:
￿
A value of the underlying type
￿
A value of the same nullable type
￿The value null
The following code shows an example of each of the three types of assignment.
int? MyI1, MyI2, MyI3;
MyI1 = 28; // Value of underlying type
MyI2 = MyI1; // Value of nullable type
MyI3 = null; // Null
Console.WriteLine("MyI1: {0}, MyI2: {1}", MyI1, MyI2);
Console.WriteLine("MyI3 {0} null", MyI3 == null ? "is" : "is not");
This code produces the following output:
MyI1: 28, MyI2: 28
MyI3 is null
Search WWH ::




Custom Search