Does the C # compiler provide a default constructor for reference types (if one is not specified) or the CLR?

I believe ( correct me if I am wrong ), according to the C # rule for value types there is no default constructor. The CLR will determine the value for zeroing the field values.

For reference type:

class Test
{

  private string Name;

}

Will a default C # or CLR constructor be provided?

+5
source share
2 answers

In the CLI specification, a constructor is required for non-static classes, so by default, the default constructor will be generated by the compiler, unless you specify another constructor.

This way the default constructor will be provided by the C # compiler for you.

+11

, , . ( , ):

.method public hidebysig specialname rtspecialname instance void .ctor() cil managed
{
    .maxstack 8
    L_0000: ldarg.0 
    L_0001: call instance void [mscorlib]System.Object::.ctor()
    L_0006: ret 
}

ctor 0, .

+3

All Articles