static void Main(string[] args) { // EagerSingleton EagerSingleton eagerSingleton = EagerSingleton.GetInstance(); // LazySingleton LazySingleton lazySingleton = LazySingleton.GetInstance(); Console.ReadLine(); }
static void Main(string[] args) { LazySingleton a1 = LazySingleton.GetInstance; LazySingleton a2 = LazySingleton.GetInstance; if (a1.Equals(a2)) { Console.WriteLine("a1, a2 are the same object"); } Console.WriteLine("Hello World!"); }
private void CallLazySingleton() { LazySingleton s1 = LazySingleton.Instance; LazySingleton s2 = LazySingleton.Instance; if (s1 == s2) { Console.WriteLine("Singleton works, both variables contain the same instance."); } else { Console.WriteLine("Singleton failed, variables contain different instances."); } }