static void Main(string[] args) { Singleton newInstance = Singleton.getInstance(); Console.WriteLine($"Instance Id : {newInstance.GetHashCode()}"); Console.WriteLine(PrintLinkedList(newInstance.getLetterList())); LinkedList <string> playerOneTiles = newInstance.getTiles(7); Console.WriteLine($"Player 1 : {PrintLinkedList(playerOneTiles)}"); Console.WriteLine(PrintLinkedList(newInstance.getLetterList())); //Player 2 Singleton instanceTwo = Singleton.getInstance(); Console.WriteLine($"Instance Id : {instanceTwo.GetHashCode()}"); Console.WriteLine(PrintLinkedList(newInstance.getLetterList())); LinkedList <string> playerTwoTiles = newInstance.getTiles(7); Console.WriteLine($"Player 2 : {PrintLinkedList(playerTwoTiles)}"); Console.ReadKey(); }
static void Main(string[] args) { Singleton s1 = Singleton.Instance; Singleton s2 = Singleton.Instance; Console.WriteLine("s1: " + s1.GetHashCode() + ", s2: " + s2.GetHashCode()); s1.doSomething(); s2.doSomething(); Console.WriteLine("\n\nTesting Singleton Pattern use multiple threading."); Task.Run(() => { System.Threading.Thread.Sleep(5000); SingletonThreadSafe s12 = SingletonThreadSafe.Instance; Console.WriteLine($"first: {s12.GetHashCode()}"); s12.doSomething(); }); Task.Run(() => { System.Threading.Thread.Sleep(5000); SingletonThreadSafe s22 = SingletonThreadSafe.Instance; Console.WriteLine($"second: {s22.GetHashCode()}"); s22.doSomething(); }); Console.ReadLine(); }