gpt4 book ai didi

c# - 我怎样才能更好地从集合中的集合中获取集合?

转载 作者:太空狗 更新时间:2023-10-30 00:54:14 25 4
gpt4 key购买 nike

正如您从下面的代码中看到的,我正在从列表中的列表中构建对象集合。想知道是否有更好的方法来编写这个讨厌的方法。

提前干杯

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;
}

最佳答案

使用SelectMany

private List<ListINeed> GetListINeed(Guid clientId)
{
return someobject.SelectMany(p=> p.subcollection)
.Select(p=>p.subObject).ToList();
}

关于c# - 我怎样才能更好地从集合中的集合中获取集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13625143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com