zoukankan      html  css  js  c++  java
  • 学习面向对象思想

    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);                    }
        }

  • 相关阅读:
    Python易忽略要点记录二
    Python使用的几个小技巧
    MySQL内容整理二
    C++面向对象知识总结
    AssemblyInfo 的作用
    中国新年第一篇
    function函数的运用
    C语言1博客作业03
    C语言1博客作业02
    .C# 拷贝一个图片到指定文件夹下(IO文件操作实例)
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3105358.html
Copyright © 2011-2022 走看看