Recent Posts

Categories

Archives

Calendar

July 2007
M T W T F S S
« Jun   Jan »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Search


Meta

Simple Thread Safe Singleton

This is simple but should work:

public sealed class Singleton
{
   private static Singleton _instance = new Singleton();

   private Singleton() { }

   public static Singleton Instance
   {
      get
      {
         return _instance;
      }
   }
}

As the CLR synchronises static constructors it is thread safe. Also static constructors are not called until the types is accessed to you have lazy instantiation (use nesting if there are other static methods).