Declare a nullable type by adding the ? type modifier in a value type declaration. : Nulllable « Data Types « C# / C Sharp






Declare a nullable type by adding the ? type modifier in a value type declaration.

  

using System;
public class MainClass {
    double? variable1 = null;

    static void Main() {
        int? variablea = null;
        Console.WriteLine(variablea.HasValue); // false
        int variableb = variablea ?? 5;
        Console.WriteLine(variableb); // 5
    }
}

   
  








Related examples in the same category

1.Nullable variable
2.Nullable bool Types
3.Nullable int Types
4.Nulllable HasValue
5.Is it Nullable
6.Nullable extension: Has Value And Equals