static void Main(string[] args) { SingletonObject ObjSingleton = SingletonObject.getInstance(); ObjSingleton.ShowMessage(); Console.ReadLine(); }
static void Main(string[] args) { SingletonObject singletonObject = SingletonObject.Instance; singletonObject.DoSomething(); SingletonObject.Instance.DoSomething(); var s = SingletonObject.Instance; s.DoSomething(); }
/// <summary> /// Singleton DP Demonstration /// </summary> /// <param name="args"></param> static void Main(string[] args) { /* * * //You would normally do this but method is private * SingleObject singleObject = new SingleObject(); */ // Returns the instance var SingletonObject so = SingletonObject.getInstance(); so.showMessage(); }
static void Main(string[] args) { var myObj = SingletonObject.GetInstance(); myObj.Name = "My Singleton Object"; var myObj2 = SingletonObject.GetInstance(); var myObj3 = SingletonObject.GetInstance(); Console.WriteLine(myObj.Name); Console.WriteLine(myObj2.Name); Console.WriteLine(myObj3.Name); }