Dynamic initialization. : Variable Definition : Language Basics C# Examples


C# Examples » Language Basics » Variable Definition »

 

Dynamic initialization.





Declare two or more variables using the same declaration statement. Just separate their names by commas:




    
int  x,  y;  //  both  declared  using  one  statement
    
   
  
   





    
using  System;    
    
class  Example  {    
    public  static  void  Main()  {    
        double  s1  =  123.0,  s2  =  1234.0;  
    
        //  dynamically  initialize  hypot    
        double  hypot  =  Math.Sqrt(  (s1  *  s1)  +  (s2  *  s2)  );  
    
        Console.Write("Hypotenuse  of  triangle  with  sides  "  +  
                                    s1  +  "  by  "  +  s2  +  "  is  ");  
  
        Console.WriteLine("{0:#.###}.",  hypot);  
  
    }    
}
    
   
  
   



Output

Hypotenuse of triangle with sides 123 by 1234 is 1240.115.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Variable Definition