Answers for "singleton design pattern c# volatile"

C#
0

singleton design pattern c# volatile

public sealed class Singleton
{
   private static volatile Singleton instance;
   private static object syncRoot = new Object();

   private Singleton() {}

   public static Singleton Instance
   {
      get 
      {
         if (instance == null) 
         {
            lock (syncRoot) 
            {
               if (instance == null) 
                  instance = new Singleton();
            }
         }

         return instance;
      }
   }
}
Posted by: Guest on June-15-2020

C# Answers by Framework

Browse Popular Code Answers by Language