views:

38

answers:

0

Hi,

This post is for all .NET developers who often tries to reinvent the utility classes which already does by many programmers around the world.

I request everyone to please post your favourite utility classes(with code) here.

To start the show, Given below is the c# code for multithreaded singleton.

Multithreaded Singleton



using System;

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;
      }
   }
}


Thanks, Mahesh