日期:2014-05-18  浏览次数:20921 次

List集合的Exists方法如何使用
定义了一个List集合,类似下面是这样的数据:
List<classMaterial> materialList = new List<classMaterial>();
materialList.Add("ANAME","AModel",AAmount,"AUnit");
materialList.Add("BNAME","BModel",Bmount,"BUnit");
materialList.Add("CNAME","CModel",CAmount,"CUnit");
materialList.Add("CNAME","DModel",DAmount,"DUnit");
materialList.Add("CNAME","EModel",EAmount,"EUnit");
看到List<>里面本身带了一个Exists()方法,但是不知道怎么用?
比如我想查里面第一列 = “CName" 并且 第二列 = “DModel”的记录要怎么查呢?


------解决方案--------------------
代码相当于
C# code
private bool ExistsFunc(classMaterial v1)
{
    return v1.Name == "CName" && v1.Model == "DModel";
}

materialList.Exists(ExistsFunc);