单例模式

我们以前写过了很多中单例模式,确实都能实现我们想要的功能,但是单例模式最好的一种我觉得还是下列代码所示:

 public sealed class Singleton
    {
        Singleton()
        {
        }

        public static Singleton Instance()
        {
            {
                return Nested.instance;
            }
        }
        class Nested
        {
            static Nested()
            {
            }
            internal static readonly Singleton instance = new Singleton();
        }
    }  
}

 

posted @ 2014-07-14 23:17  等待是一生最初的苍老  阅读(93)  评论(0)    收藏  举报