Advertisement
Guest User

Untitled

a guest
Nov 21st, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03.PC_Catalog
  4. {
  5. public class Components
  6. {
  7. private string name;
  8. private string details;
  9. private decimal price;
  10.  
  11. public Components(string name, string details, decimal price)
  12. {
  13. this.Name = name;
  14. this.Details = details;
  15. this.Price = price;
  16. }
  17. public Components(string name, decimal price) :this(name, null, price)
  18. {
  19.  
  20. }
  21. public string Name
  22. {
  23. get
  24. {
  25. return this.name;
  26. }
  27. set
  28. {
  29. if (string.IsNullOrEmpty(value))
  30. {
  31. throw new ArgumentException("You should type a name!");
  32. }
  33. else
  34. {
  35. this.name = value;
  36. }
  37. }
  38. }
  39. public string Details
  40. {
  41. get
  42. {
  43. return this.details;
  44. }
  45. set
  46. {
  47. this.name = value;
  48.  
  49. }
  50. }
  51. public decimal Price
  52. {
  53. get
  54. {
  55. return this.price;
  56. }
  57. set
  58. {
  59. if (value < 0)
  60. {
  61. throw new ArgumentException("Price cannot be a negative number!");
  62. }
  63. else
  64. {
  65. this.price = value;
  66. }
  67. }
  68. }
  69.  
  70. public string[] ArraySight()
  71. {
  72. if (string.IsNullOrEmpty(details))
  73. {
  74. return new string[] { name, price.ToString() };
  75. }
  76. else
  77. {
  78. return new string[] { name, details, price.ToString() };
  79. }
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement