public c() : base()You can even add in a call to another constructor, as in below. The single parameter instance constructor is called before the default constructor.
{
Console.WriteLine("Constructor c") ;
}
public c(int v)The use of base and this apply only to instances and not static classes. There is no instance in a static class.
{
stcint = v;
}
public c() : this(1)
{
Console.WriteLine("Constructor c") ;
}
Static Constructors and Initializers So why were the static constructors and initializers and the instance initializers called in the order c, b ,a and not the same order as the instance constructors? Because that is the order that the classes are accessed. The first class created was c. What actually happens is this.
- Static Field Initializers are executed. These might be needed in the static constructor.
- Static Constructor is called.
- The instance initializer is called.
- The base class is accessed, repeating steps 1-3.
Some Simple Rules to Remember
- Field Initializers are called before Constructors.
- Static Initializers and Constructors are called once before any instances are constructed.
- Statics are called (in a class hierarchy) in the order that classes are used.
- Instances are constructed in a hierarchy starting with the ancestor class.
On the next page : More about Using This and Base

