本文整理汇总了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());
}
示例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);
}
}
示例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();
}
}
示例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);
}
}