List<Customer> customers = new List<Customer> {
new Customer { ID="A", City="New York", Country="USA", Region="North America", Sales=9999},
new Customer { ID="B", City="Mumbai", Country="India", Region="Asia", Sales=8888},
new Customer { ID="T", City="Lima", Country="Peru", Region="South America", Sales=2002 }
};
//想对City="Mumbai",进行操作
textBox1.Text = customers.IndexOf(这里写什么?).ToString());
customers.Remove(这里写什么?);
本人是刚学习c#,请教这是泛型变量吗?如果查询其位置、删去其中符合条件的一组数据?
------解决思路----------------------
泛型+Linq?
var city = customers.FirstOrDefaut(c=>c.City=="Mumbai");
if(city!=null)
{
textBox1.Text = city.???
customers.Remove(city);
}
------解决思路----------------------
customers.RemoveAt(customers.FindIndex(x => x.city == "Mumbai"));