Guest User

Untitled

a guest
Aug 16th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using singleton to pass property values? [closed]
  2. public class ShareArray
  3. {
  4. private System.Collections.ArrayList arrayList;
  5. private string pass;
  6. private string userName
  7.  
  8. #region Property
  9. public System.Collections.ArrayList ArrayList { get{return arrayList;}}
  10. public string UserName { get{return userName;} set{userName = value;}}
  11. public string Pass { get{return pass;} set{pass = value;}}
  12. #endregion
  13.  
  14. #region Imp. signletone
  15. private static ShareArray instance;
  16. public static ShareArray Instance
  17. {
  18. get
  19. {
  20. if (instance == null)
  21. {
  22. instance = new ShareArray();
  23. }
  24. return instance;
  25. }
  26. }
  27.  
  28.  
  29. private ShareArray()
  30. {
  31. arrayList = new System.Collections.ArrayList();
  32. }
  33. #endregion
  34. }
  35.  
  36. ShareArray.Instance.Pass = "pass";
  37. ShareArray.Instance.UserName = "user name";
  38.  
  39. namespace SingletonExample
  40. {
  41. public seal class Singleton
  42. {
  43. private static Singleton _instance;
  44. private static object _syncInstance = new Object();
  45. private static ArrayList _someList = new ArrayList();
  46.  
  47. private static Singleton GetInstance()
  48. {
  49. get
  50. {
  51. if (_instance == null)
  52. {
  53. lock(_syncInstance)
  54. {
  55. _instance = new Singleton();
  56. }
  57. }
  58. return _instance;
  59. }
  60. }
  61.  
  62. public ArrayList ArrayList
  63. {
  64. get
  65. {
  66. return _someList;
  67. }
  68. set
  69. {
  70. _someList = value;
  71. }
  72. }
  73.  
  74. public Object GetValue
  75. {
  76. get
  77. {
  78. return _someList[value];
  79. }
  80. }
  81. }
  82.  
  83. }
Add Comment
Please, Sign In to add comment