[C#] Computer – Pastebin.com

Not a member of Pastebin yet? Sign Up, it unlocks many cool features! class Computer

Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

  1. class Computer

  2.     {

  3.         private string name;

  4.         private List<Component> components;

  5.         private decimal price;

  6.  

  7.         private static decimal TotalComponentsPrice(List<Component> components)

  8.         {

  9.             decimal totalPrice = 0;

  10.             foreach (var cmpt in components)

  11.             {

  12.                 totalPrice += cmpt.Price;

  13.             }

  14.  

  15.             return totalPrice;

  16.         }

  17.  

  18.         public void Init(string name, List<Component> components)

  19.         {

  20.             this.Name = name;

  21.             this.Price = TotalComponentsPrice(components);

  22.             this.Components = components;

  23.         }

  24.  

  25.         public string Name

  26.         {

  27.             get

  28.             {

  29.                 return this.name;

  30.             }

  31.             set

  32.             {

  33.                 if (string.IsNullOrEmpty(value))

  34.                 {

  35.                     throw new ArgumentNullException(“Name cannot be empty”);

  36.                 }

  37.                 this.name = value;

  38.             }

  39.         }

  40.         public decimal Price

  41.         {

  42.             get

  43.             {

  44.                 return this.price;

  45.             }

  46.             set

  47.             {

  48.                 this.price = TotalComponentsPrice(components);

  49.             }

  50.            

  51.         }

  52.         public List<Component> Components { get; set; }

  53. }

We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand

Source Article