snippets / singleton

All snippets tagged singleton (1)

  1. Singleton template

    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 }
    Posted by themadmax to c# singleton template ... saved by 1 person ... 0 comments ... 1 year
showing 10, 25, 50 items per pages

Pages : 1

Flux RSS friendsnippetLatest snippets


More...