C# 单例使用

public class Singleton
{
    #region 单例方法

    private static Singleton instance;

    private Singleton()
    {
    }

    public static Singleton Instance()
    {
        if (instance == null)
        {
            lock (typeof(Singleton))
            {
                if (instance == null)
                {
                    instance = new Singleton();
                }
            }
        }

        return instance;
    }

    #endregion
}

 

posted @ 2023-10-26 09:34  时而有风  阅读(18)  评论(0编辑  收藏  举报