A static constructor will execute before Main, but only if the class is actually being referenced by something. Eg:
class ClassWStaticCon
{
static ClassWStaticCon()
{
Console.WriteLine("Hello world!");
}
}
...
static void Main(string[] args)
{
Console.WriteLine("Hello main.");
}
Will print:
Hello main.
class ClassWStaticCon
{
public static int SomeField;
static ClassWStaticCon()
{
Console.WriteLine("Hello world!");
}
}
...
static void Main(string[] args)
{
ClassWStaticCon.SomeField = 0;
Console.WriteLine("Hello main.");
}
Will print:
Hello world! Hello main.
If you want to control the order of execution then use a Queue of Action delegates http://msdn.microsoft.com/en-us/library/018hxwa8.aspx in a single static 'initialize all pre main stuff' class.