design patterns - Singleton in C# -


i collect more variants create singleton class. please provide me best creation way in c# opinion.

thanks.

public sealed class singleton {     singleton _instance = null;      public singleton instance     {                 {             if(_instance == null)                 _instance = new singleton();              return _instance;         }     }      // default private constructor can instanctiate     private singleton() { }      // default private static constructor     private static singleton() { } } 

i have entire article on may find useful.

oh, , try avoid using singleton pattern in general, due pain testability etc :)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -