/////////////////////////////////// // // Get the Instance ...! // public static SingleInstanceClass GetInstance() { if (_inst == null) { _inst = new SingleInstanceClass(); } return(_inst); }
public static void Main(String [] args) { SingleInstanceClass p = SingleInstanceClass.GetInstance(); p.Value = 10; SingleInstanceClass q = SingleInstanceClass.GetInstance(); q.Value = 20; ///////////////////////// // // p and q should hold the same value ...! Console.WriteLine(q.Value); Console.WriteLine(p.Value); }
//~SingleInstanceClass() //{ // instanceFlag = false; //} public static SingleInstanceClass Create() { if (!instanceFlag) { sic = new SingleInstanceClass(); instanceFlag = true; return sic; } else { return null; //return sic; } }