Introduction

Null value types represented by a ? after the data type of a variable, allows the variable to have a value of null in addition to the spectrum of values that the data type can have.

Example

int? x = 5;

if (x is int)
    Console.WriteLine("x is an integer");
else
    Console.WriteLine("x is not an integer");

// x is an integer

Changing a nullable value type to a non-nullable value type

If you want to change a variable with a nullable type to a non-nullable type, use the null-coalescing operator:

int? b = 9;
int c = b ?? -1;
Console.WriteLine($"c is {c}"); //c is 9

Dealing with nullable value types when using comparison operators

When using comparison operators (<, >, <=,>=, and >=), if one of the operands or both of them are null, the end result will be false.