A nullable type assigns the value of its underlying type to its normal range and a null value.
For example,:nullable<int32> can be assigned a value of 2147483618 to 2147483618 and null. (Int?=null or int?=9)
The ability to assign null to a numeric type or Boolean is particularly useful when working with databases and other data types that contain elements that may not be assigned a value .
For example, a Boolean field in a database can store values.
Example Description:
Using System;namespace calculatorapplication{ class nullablesatshow { static void Main (string[] args) { int? num1 = null; Int? num2 =; Double? num3 = new double? (); Double? NUM4 = 3.14157; bool? Boolval = new bool? (); Console.WriteLine ("Show Values for nullable types: {0}, {1}, {2}, {3}", num1, num2, num3, num4); Console.WriteLine ("A nullable Boolean value: {0}", boolval); Console.ReadLine ();}}}
Null merge operator (??)
If the value of the first operand is null, the operator returns the value of the second operand, otherwise the value of the first operand is returned.
Using System;namespace calculatorapplication{ class nullablesatshow { static void Main (string[] args) { double? num1 = null; Double? num2 = 3.14157; Double num3; num3 = Num1?? 5.34; Console.WriteLine ("Value of num3: {0}", num3); num3 = num2?? 5.34; Console.WriteLine ("Value of num3: {0}", num3); Console.ReadLine ();}}}
C # Nullable types