日期:2014-05-20  浏览次数:20657 次

Linq菜鳥求助
_exportAppNationIdList.ForEach(p => nationIdList.Add(p.InsuredIdNumber))

這行語句的意思是什麼。

Add(p.InsuredIdNumber),這裏面的p是什麼東西?
linq

------解决方案--------------------
这句就是遍历_exportAppNationIdList里面的内容
foreach(var p in _exportAppNationIdList)
{
nationIdList.Add(p.InsuredIdNumber)
}
等价
------解决方案--------------------
_exportAppNationIdList.ForEach(p => nationIdList.Add(p.InsuredIdNumber))
就是循环将_exportAppNationIdList中的InsuredIdNumber这项添加到nationIdList中


------解决方案--------------------
p是Lambda表达式的参数。

p => nationIdList.Add(p.InsuredIdNumber)
相当于
void foo(元素的类型 p)
{
    nationIdList.Add(p.InsuredIdNumber);
}
...
_exportAppNationIdList.ForEach(foo);