Tag Archives: Design Patterns

C# : Design Patterns : Singleton Instance

Singletons in C

Use a singleton when you need one and only one instance of a class

Here is an example :

 ///<summary>Create a singleton instance of MySingleton by example</summary>
 class MySingleton {

     //singleton stored
     private static MySingleton _instance;

     private MySingleton() { };

     // public access to singleton
     public static MySingleton Instance {
           if(_instance == null)
             _instance = new MySingleton();
           return _instance;