我有以下变量:
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
*/
一个例子:
Comment comment = moderatedComments[1][0].First();
// Repository 1
// Moderation operation 0
// First moderated comment for that repository and operation
我想将所有三个维度合并为一个(IEnumerable<Comment>
),其中包含所有经过审核的注释,无论存储库或审核操作如何。
如何使用LINQ实现这一目标?
答案 0 :(得分:4)
请这样做,请:
IEnumerable<Comment>[][] moderatedComments;
var merged = moderatedComments.SelectMany(x => x).SelectMany( x => x );
// merged is IEnumerable<Comment>