Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SingletonDemo
  8. {
  9.  
  10. namespace SingletonDemo
  11. {
  12. class MainApp
  13. {
  14. static void Main(string[] args)
  15. {
  16. Singleton s1 = Singleton.Get_Instance();
  17. Singleton s2 = Singleton.Get_Instance();
  18.  
  19.  
  20. if (s1.Equals(s2))
  21. Console.WriteLine("The instances are the same!!");
  22. else
  23. Console.WriteLine("The instances are different");
  24.  
  25. Console.ReadKey();
  26. }
  27. }
  28.  
  29. sealed class Singleton
  30. {
  31. private static Singleton _instance = null;
  32.  
  33. private Singleton()
  34. {
  35.  
  36. }
  37.  
  38. public static Singleton Get_Instance()
  39. {
  40.  
  41. if (_instance == null)
  42. _instance = new Singleton();
  43.  
  44. return _instance;
  45.  
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement