C# 如何将三维数组合并到一个数组中

C# 如何将三维数组合并到一个数组中,c#,.net,arrays,linq,C#,.net,Arrays,Linq,我有以下变量: IEnumerable<Comment>[][] moderatedComments; /** * First dimension [] = The repository from where I fetched the comments (Could be more than one repository) * Second dimension [][] = The moderation operation (There can only be two operat

我有以下变量:

IEnumerable<Comment>[][] moderatedComments;
/**
* First dimension [] = The repository from where I fetched the comments (Could be more than one repository)
* Second dimension [][] = The moderation operation (There can only be two operations, so this dimension is always of size 2)
* Third dimension IEnumerable<Comment> = The moderated comments for that dimension
*/
我想将所有三个维度合并到一个IEnumerable中,其中包含所有经过审核的评论,而不考虑存储库或审核操作


如何使用LINQ实现这一点?

请这样做:

IEnumerable<Comment>[][] moderatedComments;
var merged = moderatedComments.SelectMany(x => x).SelectMany( x => x );
// merged is IEnumerable<Comment>

这不是一个多维数组,它只是…数组的数组。您能详细说明一下为什么要使用嵌套数组来表示对象图吗?向Comment类添加属性可能会更好。正如Asad所建议的那样,使用自定义对象可能会更好,如果您想要像数组一样的索引,您可以随时查看索引器属性。如果您愿意,使用Linq和进一步查询Linq会简单得多。@leppie-这也是多维的。没什么。标准的命名是“锯齿数组”,但我更喜欢数组的数组。。。。与这个问题无关——我们并不总是喜欢帮助别人射自己的脚。在元站点上查找XY问题。最后一条评论非常有用,但用确切的类型替换var是一个更强有力的声明。回答时不必遵循某些生产代码准则。
IEnumerable<Comment>[][] moderatedComments;
var merged = moderatedComments.SelectMany(x => x).SelectMany( x => x );
// merged is IEnumerable<Comment>