簡體   English   中英

如何在一個數組中合並三維數組

[英]How to merge three dimensional array in one array

我有以下變量:

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如何做到這一點?

這樣做,請:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM