C#经典的线程安全的单例模式(独身模式)实现代码

publicsealedclassSingleton{Singleton(){}publicstaticSingletonInstance{get{returnNested.instance;}}classNested{// Explicit static constructor to tell C# compiler// not to mark type as beforefieldinitstaticNested(){}internalstaticreadonlySingleton instance =newSingleton();}}

使用内嵌类,实现延迟加载;指定为readonly保证线程安全。

posted on 2014-02-14 12:16  wensky  阅读(461)  评论(0)    收藏  举报

导航