A nullable value type T? represents all values of its underlying value type T and an additional null value.

For example, you can assign any of the following three values to a bool? variable: true, false, or null.

An underlying value type T cannot be a nullable value type itself.

Test Typing with Pattern Matching

Beginning with C# 7.0, the is operator also tests an expression result against a pattern. In particular, it supports the type pattern in the following form:

Example combining nullable value type and pattern matching:

1
2
3
4
5
6
7
int i = 23;
object iBoxed = i;
int? jNullable = 7;
if (iBoxed is int a && jNullable is int b)
{
Console.WriteLine(a + b); // output 30
}

Read further here at Microsoft Docs for type testing and cast