我正在尝试在 youtube 中实现一个示例,导师做对了,但我遇到了错误。
我已经有一个私有构造函数,我的代码中不能有公共构造函数。
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;
}
}
Run Code Online (Sandbox Code Playgroud)