泛型list的删除,如何不根据索引来删除?
1 泛型类
public class DataItem<Type1, Type2>
{
public Type1 Text
{
get;
set;
}
public Type2 Value
{
get;
set;
}
}
2 list
List<DataItem<string, int>> list = new List<DataItem<string, int>>();//定义
list.Add(new DataItem<string, int> { Text = "采购", Value = 1 });//添加
list.Remove(new DataItem<string, int> { Text = "采购", Value = 1 });
// 无法删除
该怎么样删除呢?不用list.RemoveAt[0],不用索引
------解决方案--------------------list.RemoveAll((item) => { return item.Value == 1 && item.Text == "采购"; });