Recent Posts

Categories

Archives

Calendar

March 2010
M T W T F S S
« Jan    
1234567
891011121314
15161718192021
22232425262728
293031  

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).

Leave a Reply