Advertisement
msmilkoff

Components

Nov 22nd, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. class Component
  2.     {
  3.         string name;
  4.         decimal price;
  5.         string details;
  6.  
  7.         public Component(string name, decimal price, string details = null) : this(name, price)
  8.         {
  9.             this.Details = details;
  10.         }
  11.  
  12.         public Component(string name, decimal price)
  13.         {
  14.             this.Name = name;
  15.             this.Price = price;
  16.         }
  17.  
  18.         public string Name
  19.         {
  20.             get
  21.             {
  22.                 return this.name;
  23.             }
  24.             set
  25.             {
  26.                 if (string.IsNullOrEmpty(value))
  27.                 {
  28.                     throw new ArgumentNullException("Component name cannot be empty");
  29.                 }
  30.                 this.name = value;
  31.             }
  32.         }
  33.         public decimal Price
  34.         {
  35.             get
  36.             {
  37.                 return this.price;
  38.             }
  39.             set
  40.             {
  41.                 if (value <= 0)
  42.                 {
  43.                     throw new ArgumentOutOfRangeException("Component price must be a positive number");
  44.                 }
  45.                 this.price = value;
  46.             }
  47.         }
  48.         public string Details{ get; set; }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement