设计模式——单例模式

 1     internal class SingletonOne
 2     {
 3         private static SingletonOne _singleton;
 4         private SingletonOne()
 5         {
 6         }
 7 
 8         public static SingletonOne Instance
 9         {
10             get
11             {
12                 if (_singleton == null)
13                 {
14                     Interlocked.CompareExchange(ref _singleton, new SingletonOne(), null);
15                 }
16 
17                 return _singleton;
18             }
19         }
20     }

 

posted @ 2016-07-24 23:30  天空中一朵艳阳  阅读(96)  评论(0编辑  收藏  举报