I have a class named A. What the difference between these two statements?
A a = new A();
A a = default(A);
This creates a new instance of the type A by calling the default, parameterless constructor:
A a = new A();
This assigns the default value for type A to the variable a and does not call any constructor at all:
A a = default(A);
The main difference is that the default value of a type is null for reference types and a zero-bit value for all value types (so default(int) would be 0, default(bool) would be false, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With