c# - 从 IEnumerable<ObservableCollection<T>> C# 中提取项目

标签 c# linq ienumerable observablecollection

我有:

IEnumerable<ObservableCollection<PointCollection>> rings = 
    from graphic 
    in e.FeatureSet 
    select ((Polygon)e.FeatureSet.Features).Rings;

我想从每个图形中提取所有 PointCollection,并将它们合并到一个 ObservableCollection 中。像这样:

ObservableCollection<PointCollection> allRings = ?;

有没有更好的方法可以在不执行一堆嵌套的 ForEach 语句的情况下进行迭代?

最佳答案

你可以使用 SelectMany :

var allRings = new ObservableCollection<PointCollection>(
    rings.SelectMany(rings => rings)
);

关于c# - 从 IEnumerable<ObservableCollection<T>> C# 中提取项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13575518/

相关文章:

c# - 错误 :A local variable named 'Model' cannot be declared in this scope

带有 HttpWebRequest 的 C# 程序只能通过 Fiddler 工作

c# - 使用 Expression.AndAlso 聚合表达式列表时遇到问题

c# - 使用 IEnumerable<IEnumerable<string>> 的更好方法

c# - 将延迟的 IEnumerable<T> 拆分为两个序列而不重新评估?

c# - Office 加载项项目、dll 和 app.config 文件问题

c# - 使用数据集进行 Microsoft 报告

LINQ递归函数?

c# - 从 LINQ 查询结果返回单个属性

c# - 仅在一个 LINQ 表达式中获取 IEnumerable 集合的总和