当前位置: 代码迷 >> 综合 >> 线程安全的单例
  详细解决方案

线程安全的单例

热度:43   发布时间:2024-02-21 05:12:54.0

直接上代码

namespace Test
{    public class SingletonTest{object Lock = new object();public static SingletonTest _singletonTest = null;public SingletonTest CreateInstace(){if (_singletonTest == null){lock (Lock){if (_singletonTest == null){_singletonTest = new SingletonTest();}}}return _singletonTest;}}
}

 

  相关解决方案