A nullable type : Nullable : Data Type C# Examples


C# Examples » Data Type » Nullable »

 

A nullable type









    
using  System;  
  
class  MainClass{  
    public  static  void  Main()  {  
        int?  count  =  null;  
  
        if(count.HasValue)  
            Console.WriteLine("count  has  this  value:  "  +  count.Value);  
        else    
            Console.WriteLine("count  has  no  value");  
  
        count  =  100;  
  
        if(count.HasValue)  
            Console.WriteLine("count  has  this  value:  "  +  count.Value);  
        else    
            Console.WriteLine("count  has  no  value");          
    }  
}
    
   
  
   



Output

count has no value
count has this value: 100


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Nullable