Using ?? : Nullable : Data Type C# Examples


C# Examples » Data Type » Nullable »

 

Using ??









    
using  System;  
  
class  MainClass  {  
    static  double  myMethod()  {  
            Console.WriteLine("In  myMethod().");  
            return  0.0;  
    }  
  
    public  static  void  Main()  {  
        double?  defaultValue  =  1.5;  
        double  currentBalance;  
  
        currentBalance  =  defaultValue  ??  myMethod();  
        Console.WriteLine(currentBalance);  
        
        defaultValue  =  null;  
        currentBalance  =  defaultValue  ??  myMethod();  
        Console.WriteLine(currentBalance);  
        
    }  
}
    
   
  
   



Output

1.5
In myMethod().
0


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Nullable