new T()
, when T
is a value type, is not a boxing operation. It is the same thing as default(T)
. Foo x = new Foo();
, Foo x = default(Foo)
, and Foo x = Foo.Bar;
all do exactly the same thing.
Reference:
Initializing Value Types
int myInt = new int();
–or–
int myInt = 0;
Using the new operator calls the default constructor of the specific type and assigns the default value to the variable. In the preceding example, the default constructor assigned the value 0 to myInt. For more information about values assigned by calling default constructors, see Default Values Table.