Saturday, May 5, 2018

C# : How to use Nullable<> Types in .Net

A nullable Type is a data type is that contain the defined data type or the value of null.

You should note here that here variable datatype has been given and then only it can be used.

This nullable type concept is not comaptible with "var".

I will explain this with syntax in next section.

Declaration:

Any DataType can be declared nullable type with the help of operator "?". 
Example of the syntax is as Follows :- 
  1. int? i = null;  
As discussed in previous section "var" is not compatible with this Nullable Type. 

So we will have Compile Time error if we are declaring something like: -
  1. var? i = null;  
though following syntax is completely fine :- 
  1. var i = 4;  

No comments:

Post a Comment