【发布时间】:2020-11-04 04:39:57
【问题描述】:
我有一个列表中的对象列表。我想要一个基于某些条件的对象列表。
List<List<int>> lists = new List<List<int>> {
new List<int> {1, 2, 3},
new List<int> {4, 5, 6},
new List<int> {7, 8, 9},
};
如果我这样做
lists.Select(x => x.Where(y => y < 5));
我会收到List<List<int>>
但是,我实际上想要 List。
如何将所有小于 5 的元素作为List<int> 获取?
PS:我知道我可以使用 for 循环,但这不是我想要的。
【问题讨论】:
-
这能回答你的问题吗? Difference Between Select and SelectMany
-
现在,阅读答案后,这很有意义。我不确定如何将 Where() 与 SelectMany() 一起使用。谢谢!
标签: c# asp.net asp.net-mvc list