How to use Nullable<> Types in C#?

Category: C SharpHow to use Nullable<> Types in C#?
Editor">Editor Staff asked 2 years ago

How to use Nullable<> Types in C#?

1 Answers
Editor">Editor Staff answered 2 years ago

A nullable type is a data type is that contains the defined data type or the null value.

 
This nullable type concept is not compatible with “var”.
 
Any data type can be declared nullable type with the help of operator “?”. 
 
For example, the following code declares the int ‘i’ as a null.

 

  1. int? i = null;  

As discussed in the previous section “var” is not compatible with nullable types. So, if you declare the following, you will get an error.

 

  1. var? i = null;