Guest User

Untitled

a guest
Jan 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 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 SingletoneExample {
  8.  
  9. class Singleton {
  10. private static Singleton instance = new Singleton();
  11.  
  12. public int flag;
  13.  
  14. private Singleton() { }
  15.  
  16. public static Singleton getInstance() {
  17. return instance;
  18. }
  19. }
  20.  
  21. class SimpleSingleton
  22. {
  23. static void Main(string[] args)
  24. {
  25. Singleton single = Singleton.getInstance();
  26. single.flag = 10;
  27. Console.WriteLine("single flag = " + single.flag);
  28.  
  29. Singleton single1 = Singleton.getInstance();
  30. Console.WriteLine("single1 flag = " + single1.flag);
  31. Console.ReadLine();
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment