📜  c# singleton - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:14.100000             🧑  作者: Mango

代码示例2
public sealed class Singleton
{
    private static Singleton instance = null;
    private static readonly object padlock = new object();

    Singleton()
    {
    }

    public static Singleton Instance
    {
        get
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new Singleton();
                }
                return instance;
            }
        }
    }
}