snippet: view plain - save this
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 }

0 comments