Define and assign value to variables : Variable Definition : Language Basics C# Examples


C# Examples » Language Basics » Variable Definition »

 

Define and assign value to variables





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);    
    }      
}
    
   
  
   



Output

x contains 100
y contains x / 2: 50


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Variable Definition