When creating an instance of a reference type,
First allocate memory for the data fields of the instance.
Then initialize the additional fields of the object (object pointer, synchronous block index),
Finally, the instance constructor defined in the type is called to set the initialization state of the object.
When constructing an object of reference type, the memory allocated to the object that all fields is always zeroed or null before calling the instance constructor of the type.
The instance constructor can never be continued. If there is no explicit constructor in the defined class,
The c# compiler will define a default constructor, in its implementation, simply call the base class's parameterless constructor.
so:
public class SomeType{}
Equivalent to
public class SomeTyoe{
public SomeType():base(){}
}
If the class modifier is abstract, the default constructor generated by the compiler is protected, otherwise it is public.
If the base class does not provide a parameterless constructor, the derived class must display that a base class constructor is called, otherwise an error will be reported.
If it is a static class, then the class does not have an instance constructor.
Before accessing the fields of the base class in the class, the constructor of the base class must be called. If the constructor of the base class is not explicitly called,
The c# compiler will automatically generate a call to the default base class constructor, and will finally call the Object's constructor.
First allocate memory for the data fields of the instance.
Then initialize the additional fields of the object (object pointer, synchronous block index),
Finally, the instance constructor defined in the type is called to set the initialization state of the object.
When constructing an object of reference type, the memory allocated to the object that all fields is always zeroed or null before calling the instance constructor of the type.
The instance constructor can never be continued. If there is no explicit constructor in the defined class,
The c# compiler will define a default constructor, in its implementation, simply call the base class's parameterless constructor.
so:
public class SomeType{}
Equivalent to
public class SomeTyoe{
public SomeType():base(){}
}
If the class modifier is abstract, the default constructor generated by the compiler is protected, otherwise it is public.
If the base class does not provide a parameterless constructor, the derived class must display that a base class constructor is called, otherwise an error will be reported.
If it is a static class, then the class does not have an instance constructor.
Before accessing the fields of the base class in the class, the constructor of the base class must be called. If the constructor of the base class is not explicitly called,
The c# compiler will automatically generate a call to the default base class constructor, and will finally call the Object's constructor.