当前位置: 首页>>代码示例>>C#>>正文


C# Computer.AddComponent方法代码示例

本文整理汇总了C#中Computer.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Computer.AddComponent方法的具体用法?C# Computer.AddComponent怎么用?C# Computer.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Computer的用法示例。


在下文中一共展示了Computer.AddComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Computer comp = new Computer("PC 1");

            comp.AddComponent("CPU", 300m);
            comp.AddComponent("GFX", 500m);
            comp.AddComponent("RAM", 100m);

            Console.WriteLine(comp.ToString());
        }
开发者ID:mgulubov,项目名称:SoftUniCourse-OOP,代码行数:10,代码来源:PCCatalog.cs

示例2: Main

 static void Main()
 {
     Computer pc1 = new Computer("Boiko Prezident");
     pc1.AddComponent("Video Card", 250.54, "Lada");  
     pc1.AddComponent("Sound Card", 25.54, "Lada");
     pc1.AddComponent("Processor", 350, "Intel i7 mn qk");
     Computer pc2 = new Computer("Pravetz 343TT");
     pc2.AddComponent("Video Card", 250.54, "Lada");
     pc2.AddComponent("Sound Card", 125.54, "Lada");
     pc2.AddComponent("Processor", 350, "Intel i7 mn qk");
     Computer pc3 = new Computer("Stamat 1000");
     pc3.AddComponent("Video Card", 20.54, "Lada");
     pc3.AddComponent("Sound Card", 25.54, "Lada");
     pc3.AddComponent("Processor", 350, "Intel i7 mn qk");
     List<Computer> computers = new List<Computer>();
     computers.Add(pc1);
     computers.Add(pc2);
     computers.Add(pc3);
     computers = computers.OrderBy(x => x.Price).ToList();
     foreach (var computer in computers)
     {
         Computer.Print(computer);
     }
 }
开发者ID:IliyaBoyanov,项目名称:OOP,代码行数:24,代码来源:PCCatalog.cs

示例3: Main

        public static void Main(string[] args)
        {
            List<Component> components = new List<Component>();
            components.Add(new Component("HDD", 120));
            components.Add(new Component("RAM", 140));

            Computer firstPc = new Computer("HP", components);

            Computer secondPc = new Computer("DELL");
            secondPc.AddComponent(new Component("CPU", 500));
            secondPc.AddComponent(new Component("GPU", 1000));
            
            List<Computer> computers = new List<Computer>();
            computers.Add(firstPc);
            computers.Add(secondPc);

            computers.Sort();

            foreach (var item in computers)
            {
                item.Print();
                Console.WriteLine();
            }
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:24,代码来源:Program.cs

示例4: Main

    static void Main()
    {
        Console.OutputEncoding = Encoding.Unicode;

        List<Component> components = new List<Component>();
        components.Add(new Component("Motherboard", 90));
        components.Add(new Component("CPU", 120.45m));
        components.Add(new Component("RAM", 45.50m, "8 GB"));
        // components.Add(new Component(" ", 12));   // Empty name => Exception
        // components.Add(new Component("HDD", -1.1m));  // Negative price => Exception

        Computer pc = new Computer("HP", components);
        Console.WriteLine(pc);
        pc.AddComponent(new Component("added later", 1)); // Using method that allows addition of components
        Console.WriteLine(pc);

        // List<Component> emptyComponentsList = new List<Component>();
        // Computer pcWithoutComponents = new Computer("Ooops", emptyComponentsList); // Empty components list on creation => Exception

        List<Computer> catalog = new List<Computer>();
        catalog.Add(pc);

        List<Component> componentsList4 = new List<Component>();
        componentsList4.Add(new Component("GPU", 1125.5m));
        componentsList4.Add(new Component("CPU", 900));

        catalog.Add(new Computer("Expensive", componentsList4));

        List<Component> componentsList2 = new List<Component>();
        componentsList2.Add(new Component("DVD", 15.99m));
        componentsList2.Add(new Component("GPU", 255.1m));

        catalog.Add(new Computer("Cheap", componentsList2));

        List<Component> componentsList3 = new List<Component>();
        componentsList3.Add(new Component("RAM", 52.19m));
        componentsList3.Add(new Component("SSD", 550));

        catalog.Add(new Computer("Average", componentsList3));

        catalog.Sort(); // Icomparable interface implemented on Computer class

        foreach (var computer in catalog)
        {
            Console.WriteLine(computer);
        }
    }
开发者ID:hkostadinov,项目名称:SoftUni,代码行数:47,代码来源:PCCatalog.cs


注:本文中的Computer.AddComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。