示例#1
0
        static void Main(string[] args)
        {
            List<Component> parts = new List<Component>()
            {
                new Component("CPU", 123.4M, "good"),
                new Component("RAM", 23.4M, "bad"),
                new Component("Screen", 13.4M),
                new Component("CD", 12.4M, "nice"),
                new Component("Motherboard", 1213.4M)
            };

            Computer myComputer = new Computer("My Pc", parts);
            Computer newComputer = new Computer("Other PC");
            Computer newComp = new Computer("New PC", new List<Component>()
            {
                new Component("CPU", 0.4M, "good"),
                new Component("RAM", 0.004M, "bad"),
            });

            myComputer.GetName();
            myComputer.GetComponents();
            myComputer.GetPrice();
            Console.WriteLine();

            newComputer.GetName();
            newComputer.GetComponents();
            newComputer.GetPrice();
            Console.WriteLine();

            List<Computer> computers = new List<Computer>() { myComputer, newComputer, newComp };
            computers.Sort((x, y) => (int)(x.Price - y.Price));
            computers.ForEach(Console.WriteLine);
        }
示例#2
0
        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()));
        }
示例#3
0
        static List<Computer> AddComputers()
        {
            List<Computer> computers = new List<Computer>();
            string exitCommand = null;

            do
            {
                Console.Write("Enter computer name: ");
                string name = Console.ReadLine();

                List<Component> components = AddComponents();

                Computer computer = new Computer(name, components);
                computers.Add(computer);

                Console.Write("Do you want to add another computer ? y/n: ");
                exitCommand = Console.ReadLine();

                Console.WriteLine();
            }
            while (exitCommand != "n" && exitCommand != "N");

            return computers;
        }