nullables in c# | #Mortaltech | #12



nullables in c# | #Mortaltech | #12

nullables in c# | #Mortaltech | #12

nullables in c# | #Mortaltech | #12

As you know, a value type cannot be assigned a null value. For example, int i = null will give you a compile time error.

C# 2.0 introduced nullable types that allow you to assign null to value type variables. You can declare nullable types using

?? Operator
Use the ‘??’ operator to assign a nullable type to a non-nullable type.

Example: ?? operator with Nullable Type
int? i = null;

int j = i ?? 0;

Console.WriteLine(j);

You can also find me here:
Instagram: MortalsTech
Facebook: MortalTech
Twitter: Mortalstech