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);
}
}
The value of i is: 0
7.11.new |
| 7.11.1. | Use new with a value type. |