static void Main() { Component myGpu = new Component("Intel HD Graphics", "Integrated chip", 499.0m); Component myCpu = new Component("Intel 2117U", 600.0m); Component myRam = new Component("4GB RAM Samsung", "DDR3 1600MHz", 300.0m); Computer myComp = new Computer("Samsung", new List<Component> { myGpu, myCpu, myRam }); Component gpu = new Component("nVidia GT880M", "2GB VRAM", 800.0m); Component cpu = new Component("Intel Core i7", 700.0m); Component ram = new Component("16GB RAM", "DDR4 2400MHz", 600.0m); Computer comp = new Computer("Lenovo", new List<Component> {gpu, cpu, ram}); List<Computer> computers = new List<Computer>() { myComp, comp }; computers.OrderByDescending(computer => computer.Price).ToList().ForEach(computer => Console.WriteLine(computer.ToString())); }
static List<Component> AddComponents() { List<Component> components = new List<Component>(); string exitCommand = null; do { Console.Write("Enter component name: "); string name = Console.ReadLine(); Console.Write("Enter component description (optional): "); string description = Console.ReadLine(); Console.Write("Enter component price: "); decimal price = decimal.Parse(Console.ReadLine()); Component component = new Component(name, description, price); components.Add(component); Console.Write("Do you want to add another component ? y/n: "); exitCommand = Console.ReadLine(); } while (exitCommand != "n" && exitCommand != "N"); return components; }