2
我試圖在youtube中實現example,導師說得對,但是出現錯誤。
我已經有一個私人構造函數,我不能在我的代碼中有公共構造函數。懶惰初始化類型沒有公共參數的構造函數
private static int _InstanceCount = 0;
private SingletonDemo1()
{
_InstanceCount++;
Console.WriteLine("Instance Count: " + _InstanceCount.ToString());
}
private static readonly Lazy<SingletonDemo1> _Instance = new Lazy<SingletonDemo1>();
public static SingletonDemo1 Instance
{
get
{
return _Instance.Value;
}
}