正如您从下面的代码中看到的,我正在从列表中的列表中构建一个对象集合。想知道是否有更好的方法来编写这个讨厌的方法。
提前干杯
private List<ListINeed> GetListINeed(Guid clientId)
{
var listINeed = new List<objectType>();
someobject.All(p =>
{
p.subcollection.All(q =>
{
listINeed.Add(q.subObject);
return true;
});
return true;
});
return listINeed;
}发布于 2012-11-29 19:53:08
怎么样
return someobject.SelectMany(so=>so.subcollection).Select(o=>o.subObject).ToList();这实际上消除了对函数的需求,除非您计划在其中执行其他操作(正如clientId参数所暗示的那样)。
https://stackoverflow.com/questions/13625143
复制相似问题