Define and assign value to variables : Variable Definition « Language Basics « C# / CSharp Tutorial






The general form of initialization is shown here:

type var = value;
using System; 
 
class MainClass {   
  public static void Main() {   
    int x;             // declares a variable  
    int y;             // declares another variable  
  
    x = 100;           // this assigns 100 to x 
  
    Console.WriteLine("x contains " + x);   
  
    y = x / 2;  
  
    Console.Write("y contains x / 2: ");  
    Console.WriteLine(y);  
  }   
}
x contains 100
y contains x / 2: 50








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