I've written a class like this:
class Singleton
{
private Singleton()
{
Console.WriteLine("Initialized.");
Singleton.num++;
}
public static uint num;
private static Singleton instance = new Singleton();
public static Singleton Instance
{
get { return Singleton.instance; }
private set { }
}
}
And in my main method, if I wrote like this:
Console.WriteLine("====================");
Singleton s = Singleton.Instance;
Console.WriteLine("====================");
//Console.WriteLine(Singleton.num);
I got a output like:
====================
Initialized.
====================
But if I uncomment the last line, I'll got a output like this:
Initialized.
====================
====================
1
Why the constructor was inkoved before any process in the second case? And why the last line will effect its previous procedures?