Use new with a value type. : new « Class « C# / CSharp Tutorial






The new operator has this general form:

class-var = new class-name( );
  1. The class-var is a variable of the class type being created.
  2. The class-name is the name of the class that is being instantiated.
  3. 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); 
  }  
}
The value of i is: 0








7.11.new
7.11.1.Use new with a value type.