• 学习面向对象思想


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

  • 相关阅读:
    [BZOJ3757] 苹果树
    [WC2013]糖果公园
    [SCOI2005]王室联邦
    luogu P2709 小B的询问
    [国家集训队]小Z的袜子
    [SDOI2009]HH的项链(莫队)
    [国家集训队]数颜色 / 维护队列(莫队)
    setting>SSH>sessions setting>勾选ssh Keepalive[ MobaXterm】设置保持SSH连接
    解决SSH自动断线,无响应的问题。
    Linux下使用bcwipe擦除磁盘空间
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3105358.html
Copyright © 2020-2023  润新知