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;
}
}