C# 我常用的单例模式

public class TestEditor
{
    private static TestEditor instance;
    private static readonly object syncRoot = new object();
    
    public static TestEditor GetInstance()
    {
         if (instance == null)
         {
             lock (syncRoot)
             {
                 if (instance == null)
                 {
                     instance = new TestEditor();
                 }
             }
         }
         return instance;
     }
}

 

posted @ 2024-07-05 21:03  东经115  阅读(2)  评论(0编辑  收藏  举报