//本人有以下自定义类型
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();