Tag Archives: c#

C# Singleton

Para el despistado:

 

public class MySingletonClass
{        
        private static MySingletonClass instance;

        public static readonly object Padlock = new object();

        public static MySingletonClass Instance
        {
            get
            {
                lock (Padlock)
                {
                    if (instance != null)
                    {
                        return instance;
                    }

                    instance = new MySingletonClass();
                    return instance;
                }
            }
        }
}