学习面向对象思想
2013-05-29 09:16
288 查看
static void Main(string[] args)
{
List<Computer> list = GetComputer();
Console.WriteLine("请输入要购买电脑的信息 如:品牌、型号、价位、颜色");
string writeInfo = Console.ReadLine();
List<Computer> showComputer = new List<Computer>();
foreach (Computer item in list)
{
if (writeInfo == item.Brand) { showComputer.Add(item); }
if (writeInfo == item.Model) { showComputer.Add(item); }
if (writeInfo ==item.Price.ToString()) { showComputer.Add(item); }
if (writeInfo == item.Color) { showComputer.Add(item); }
}
Console.WriteLine("符合您要求的电脑:");
foreach (Computer item in showComputer)
{
Console.WriteLine(item.showComputer());
}
Console.ReadKey();
}
private static List<Computer> GetComputer()
{
List<Computer> list = new List<Computer>();
Computer comasus=new Computer("ASUE","Y系列",4200,"蓝色");
Computer comlenovo=new Computer("Lenovo","Y系列",6000,"黑色");
Computer comlenovo1=new Computer("Lenovo","E系列",4500,"黑色");
Computer comarce=new Computer("Arce","N系列",4000,"紫色");
list.Add(comasus);
list.Add(comlenovo);
list.Add(comlenovo1);
list.Add(comasus);
return list;
}
Computer这是新建了一个类库里的一个Computer类
public class Computer
{
public string Brand { set; get; }
public string Model { set; get; }
public double Price { set; get; }
public string Color { set; get; }
public Computer() { }
public Computer(string brand, string model, double price, string color)
{
Brand = brand; Model = model; Price = price; Color = color;
}
public string showComputer()
{
return string.Format("电脑品牌:{0};系列:{1};价格:{2};颜色:{3}",Brand,Model,Price,Color);
}
}
{
List<Computer> list = GetComputer();
Console.WriteLine("请输入要购买电脑的信息 如:品牌、型号、价位、颜色");
string writeInfo = Console.ReadLine();
List<Computer> showComputer = new List<Computer>();
foreach (Computer item in list)
{
if (writeInfo == item.Brand) { showComputer.Add(item); }
if (writeInfo == item.Model) { showComputer.Add(item); }
if (writeInfo ==item.Price.ToString()) { showComputer.Add(item); }
if (writeInfo == item.Color) { showComputer.Add(item); }
}
Console.WriteLine("符合您要求的电脑:");
foreach (Computer item in showComputer)
{
Console.WriteLine(item.showComputer());
}
Console.ReadKey();
}
private static List<Computer> GetComputer()
{
List<Computer> list = new List<Computer>();
Computer comasus=new Computer("ASUE","Y系列",4200,"蓝色");
Computer comlenovo=new Computer("Lenovo","Y系列",6000,"黑色");
Computer comlenovo1=new Computer("Lenovo","E系列",4500,"黑色");
Computer comarce=new Computer("Arce","N系列",4000,"紫色");
list.Add(comasus);
list.Add(comlenovo);
list.Add(comlenovo1);
list.Add(comasus);
return list;
}
Computer这是新建了一个类库里的一个Computer类
public class Computer
{
public string Brand { set; get; }
public string Model { set; get; }
public double Price { set; get; }
public string Color { set; get; }
public Computer() { }
public Computer(string brand, string model, double price, string color)
{
Brand = brand; Model = model; Price = price; Color = color;
}
public string showComputer()
{
return string.Format("电脑品牌:{0};系列:{1};价格:{2};颜色:{3}",Brand,Model,Price,Color);
}
}
相关文章推荐
- UML学习笔记(三):运用面向对象思想
- 学习笔记-面向对象思想
- UML学习笔记(三):运用面向对象思想
- c#学习 9/22 面向对象思想
- 【学习java编程思想】day_1面向对象程序设计的方法
- JAVA基础第五天学习日记_面向对象开发思想、匿名对象、封装、私有、构造函数
- 黑马程序员--Java学习笔记之面向对象思想(单例模式详解、匿名对象、静态、final)
- 黑马程序员_java面向对象思想学习总结
- Java编程学习笔记-2.面向对象-[2-1]面向对象思想
- 黑马程序员_学习笔记2交通灯系统中面向对象思想的理解以及工厂模式的应用
- 面向对象思想学习总结(超赞!!!)
- 黑马程序员--Java学习笔记之面向对象思想(多态、内部类、匿名内部类、异常类)
- [学习笔记]Java面向对象思想和内存模型
- 从面向过程到面向对象再到UML来看待英语学习,思想才是王道
- OC学习--<猜拳游戏> 之 通过面向对象思想实现 2.0版本
- 黑马程序员——零基础学习iOS开发——10 Object-C 面向对象思想、OC语法简介、对象、类、
- 从面向过程到面向对象再到UML来看待英语学习,思想才是王道
- 学习笔记-面向对象基本思想
- UML学习笔记(三):运用面向对象思想
- OC学习--<猜拳游戏> 之 通过面向对象思想实现