Use new with a value type. : New : Class C# Examples


C# Examples » Class » New »

 

Use new with a value type.





The new operator has this general form:




    
class-var  =  new  class-name(  );
    
   
  
   


The class-var is a variable of the class type being created.
The class-name is the name of the class that is being instantiated.
The class name followed by parentheses specifies the constructor for the class.





    
using  System;  
  
class  MainClass  {    
    public  static  void  Main()  {    
        int  i  =  new  int();  //  initialize  i  to  zero  
  
        Console.WriteLine("The  value  of  i  is:  "  +  i);  
    }    
}
    
   
  
   



Output

The value of i is: 0


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» New