null unification : Nullable « Data Type « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

public class MainClass
{
   public static void Main(){
        int? x1 = null;
        int? x2 = new int?();
        int? y1 = 55;
        int? y2 = new int?(55);

        Console.WriteLine("{0}...{1}...{2}...{3}", x1, x2, y1, y2);

        Console.WriteLine("x1 == null? {0}", x1 == null);
        object x1o = x1; 
        Console.WriteLine("x1o == null? {0}", x1o == null);

        Console.WriteLine("{0}...{1}", x1.GetType(), x1o.GetType());
   }

}
......55...55
x1 == null? True
x1o == null? True

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an ob
ject.
   at MainClass.Main()








2.54.Nullable
2.54.1.null unification
2.54.2.Nullable long
2.54.3.Nullable Struct
2.54.4.Nullable Types Access: Explicitly use properties
2.54.5.Nullable Types Access: shortcut syntax
2.54.6.Nullable Types Assignment
2.54.7.Null Coalescing Operator
2.54.8.A nullable type
2.54.9.Use nullable objects in expressions: result contains null, because one operand is null
2.54.10.Assign value to nullable int
2.54.11.Using ??