MSDN で、シングルトン クラスを作成する 2 つの方法を見つけました。
public class Singleton {
private static Singleton instance;
private Singleton() {}
public static Singleton Instance {
get {
if (instance == null)
instance = new Singleton();
return instance;
}
}
}
と
public sealed class Singleton {
private static readonly Singleton instance = new Singleton();
private Singleton(){}
public static Singleton Instance {
get { return instance; }
}
}
私の質問は: 最初に使用する前に、このオブジェクトを作成する静的コンストラクターを使用できますか?