讨教 List 的 exist 写法

.Net技术 码拜 8年前 (2016-07-12) 985次浏览
//本人有以下自定义类型

public class theTypeNameMsg
{
	public string theTypeName { set; get; }  //姓名
	public double KuCun { set; get; }  //库存数量
	public theTypeNameMsg(string T_theTypeName, double T_KuCun)
	{
		theTypeName = T_theTypeName;
		KuCun = T_KuCun;
	}
}   
     
List<theTypeNameMsg> t1 = new List<theTypeNameMsg>() { 
new theTypeNameMsg("小明", 95), new theTypeNameMsg("张三", 91) 
};
List<theTypeNameMsg> t2 = new List<theTypeNameMsg>() { 
new theTypeNameMsg("小明", 80), new theTypeNameMsg("张三", 82), new theTypeNameMsg("李四", 77) 
};
 
 
List<theTypeNameMsg> t3 =  ........// 从 t2 中提取在 t1 中存在人名的记录,最终t3的结果应该是 ("小明", 80), ("张三", 82)
解决方案

30

var t3 = t2.FindAll(x => t1.Exists(y => y.theTypeName == x.theTypeName)).ToList();

10

var t3 = t2.Join(t1, a => a.theTypeName, b => b.theTypeName, (a,b) => a).ToList();

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明讨教 List 的 exist 写法
喜欢 (0)
[1034331897@qq.com]
分享 (0)