using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListT
{
//请设计一个笔记本类,使用泛型集合存储5个笔记本对象,遍历集合并输出。
class Notebook
{
public string color { get; set; }//颜色
public string price { get; set; }//价格
public string cpu { get; set; }//品牌
public float weight { get; set; }//重量
public string brand { get; set; }//品牌
public string model { get; set; }//型号
public Notebook(string color, string price, string cpu, float weight, string brand, string model)
{
this.color = color;
this.price = price;
this.cpu = cpu;
this.weight = weight;
this.brand = brand;
this.model = model;
}
public Notebook()
{
}
}
class TestList
{
public void CreateCourse()
{
Notebook notebook1 = new Notebook();
notebook1.brand = "联想(Lenovo)";
notebook1.model = "小新Pro13锐龙版";
notebook1.price = "¥4499.00";
notebook1.weight = 2.08f;
notebook1.color = "黑色";
notebook1.cpu = "R5-3550H";
Notebook notebook2 = new Notebook()
{
brand = "联想(Lenovo)",
model = "小新Air14",
price = "¥5299.00",
weight = 2.18f,
color = "银色",
cpu = "i5-1035G1"
};
Notebook notebook3 = new Notebook(
//string color,string price,string cpu,float weight,string brand
"灰色", "¥4299.00", "AMD锐龙5 3500U", 2.02f, "华为(HUAWEI)", "华为MateBook D");
Notebook notebook4 = new Notebook(
"魅海星蓝", "¥4599.00", "锐龙R5 3550H ", 1.5f, "荣耀", "MagicBook Pro");
Notebook notebook5 = new Notebook(
"黑色", "¥5699.00", "I5-9300H", 3.63f, "宏碁(Acer)", "暗影骑士4");
Notebook[] notebooksArray = new Notebook[] {notebook1,notebook2,notebook3,notebook4,notebook5};
List<Notebook> notebooksList = notebooksArray.ToList();
//notebooksList.Remove(notebook3);//对象删除
//notebooksList.RemoveAll(c=>c.brand== "宏碁(Acer)");//条件删除
//notebooksList.RemoveAt(2);//根据索引删除
//notebooksList.RemoveRange(index,count)//指定范围也就是索引起始位,合计删除数。
foreach (var item in notebooksList)
{
Console.WriteLine($"{item.brand}-{item.model}-{item.cpu}-{item.price}-{item.color}-{item.weight}kg,\n");
}
}
}
}