Dynamic initialization. : Variable Definition « Language Basics « C# / CSharp Tutorial






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); 
 
  }  
}
Hypotenuse of triangle with sides 123 by 1234 is 1240.115.








1.8.Variable Definition
1.8.1.Variable definition
1.8.2.Define and assign value to variables
1.8.3.Dynamic initialization.