一剑飞虹

道可道非常道,名可名非常名
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#中不需要用锁的线程安全的Singleton设计模式!

Posted on 2007-01-18 11:48  greatqn  阅读(146)  评论(0编辑  收藏  举报

http://www.cnblogs.com/kevinwan/archive/2007/01/17/CSharpSingleton.html

实现代码:

 

 1     public class Singleton
 2     {
 3         private static class LazyHolder
 4         {
 5             public static readonly Singleton Instance = new Singleton();
 6         }
 7 
 8         private Singleton()
 9         {
10         }
11 
12         public static Singleton GetInstance()
13         {
14             return LazyHolder.Instance;
15         }
16     }