Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace TestShit
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. //Example arsa = Test<Example>.GetInstance(3);
  15. var a = Singleton<Example>.GetInstance(4);
  16. var f = Singleton<Example>.GetInstance(47);
  17. var news = new Example(57);
  18.  
  19. }
  20.  
  21. class Example
  22. {
  23. int a;
  24. public Example()
  25. {
  26.  
  27. }
  28. public Example(int a)
  29. {
  30. this.a = a;
  31. }
  32. }
  33.  
  34. class MyClass
  35. {
  36.  
  37. }
  38. class Singleton<T> where T:new()
  39. {
  40. static T instance;
  41. public static T GetInstance()
  42. {
  43. if (instance == null)
  44. {
  45. instance = (T)Activator.CreateInstance(typeof(T), null);
  46. }
  47. return instance;
  48. }
  49. public static T GetInstance(int a)
  50. {
  51. if (instance == null)
  52. {
  53. instance = (T)Activator.CreateInstance(typeof(T), a);
  54. }
  55. return instance;
  56. }
  57.  
  58.  
  59.  
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement