As you can see from my nickname I'm newbie actually learning about Singleton pattern, where I got one problem. Before I've learned that static constructors are always executed before the standard constructors, but in this code below, the result is different, first I see the "Insta" string then the "Static", why does it happen ?
sealed class Singleton
{
private static readonly Singleton instance;
private Singleton()
{
Console.WriteLine("Insta");
}
static Singleton()
{
instance = new Singleton();
Console.WriteLine("Static");
}
public static Singleton Instance
{
get
{
return instance;
}
}
}
class Program
{
static void Main()
{
Singleton s1 = Singleton.Instance;
}
}