【发布时间】:2012-10-19 17:33:16
【问题描述】:
我有课
public class Foo
{
public IList<Foo> Items { get; set; }
}
public class FooList
{
public IList<Foo> Items { get; set; }
}
我希望能够在一个列表中获取所有 Foo 对象,而不是层次结构。
我试过了
IEnumerable<Foo> result = Items.SelectMany(f => f.Items);
但这只是让我获得该特定对象中的项目 - 它不会获得所有子对象中的所有项目。
我也试过
IEnumerable<Foo> result = Items.SelectMany(t => t)
但我得到了错误:
无法从用法中推断方法“System.Linq.Enumerable.SelectMany(System.Collections.Generic.IEnumerable, System.Func>)”的类型参数。尝试明确指定类型参数。
【问题讨论】:
-
一个 FooList 有一个 foo 列表。每个 Foo 也有一个 foo 列表,每个 foo 都有一个 foo 列表...
标签: linq