The specification states:
The static constructor for a class executes at most once in a given application domain. The execution of a static constructor is triggered by the first of the following events to occur within an application domain:
- An instance of the class is created.
- Any of the static members of the class are referenced.
Because you are not referencing any of the members of the base class, the constructor is not being excecuted.
Try this:
public abstract class Foo
{
static Foo()
{
Console.Write("4");
}
protected internal static void Baz()
{
// I don't do anything but am called in inherited classes'
// constructors to call the Foo constructor
}
}
public class Bar : Foo
{
static Bar()
{
Foo.Baz();
Console.Write("2");
}
public static void DoSomething()
{
/*...*/
}
}
For more information: