snippets / Singleton template

Language: C# - First posted by themadmax on 2007-11-9 14:50 (1 year)
Link to the snippet: http://www.friendsnippets.org/snippet/117/

Singleton template inplementation

 1     public class Singleton<T> where T : new()
2 {
3 static T _instance = default(T);
4
5 protected Singleton()
6 {
7 }
8
9 public static T Instance
10 {
11 get
12 {
13 if (_instance == null)
14 {
15 _instance = new T();
16 }
17 return _instance;
18 }
19 }
20 }
21
22 public class MySingleton : Singleton<MySingleton>
23 {
24 public void hello() { Debug.WriteLine("Hello"); }
25 }
In order to post a comment, you should have a friendsnippet account. Please sign-in.

0 comments

Nov '07
  • Singleton template inplementation

Common Tags



snippet History

Nov '07