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

Previous
Previous

Vista "Windows Complete PC Restore" fails with "No valid backup locations could be found"

Next
Next

Run this program as program as an administrator