c# - 是否有执行 .SelectMany(x => x) 的 Linq 方法?

标签 c# linq

我需要展平相同类型的可枚举。在 FP 中,它将是一个标准函数 concat (http://msdn.microsoft.com/en-us/library/ee353462.aspx)。我在 C# (Linq) 中做什么?

最佳答案

假设您的意思是“无需指定 x => x”:不 - 但您可以写一个:

public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> source) {
    return source.SelectMany(x => x);
}

编辑:但也许无参数-SelectMany 是一个更清晰的名称,以保持一致性:

public static IEnumerable<T> SelectMany<T>(this IEnumerable<IEnumerable<T>> source) {
    return source.SelectMany(x => x);
}

关于c# - 是否有执行 .SelectMany(x => x) 的 Linq 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26379719/

相关文章:

C# HttpWebRequest 显示 404,但可以在浏览器中访问网站

C# XML 查找第一个元素后代

c# - 使用Linq从等长数组中获取不同元素的索引

C# LINQ 问题,为什么这里需要 new?

c# - 无法删除 Windows 应用商店应用程序中的文件 - 访问被拒绝。 (HRESULT : 0x80070005 (E_ACCESSDENIED))

c# - 分割GPS路径数据

linq - 使用 Expression.Lambda() 编译委托(delegate) - 参数超出范围,但真的是这样吗?

mysql - 在 Entity Framework 6 中左联接

c# - OxyPlot:如何使用轴标签格式化程序并显示 Y 标签?

c# - 为什么 sizeof(Point) 是 8?