[英]C# LINQ multiple arrays to simple list of objects
I have an array of objects List<SlovnikWords>
, here is the model: 我有一个对象数组
List<SlovnikWords>
,这是模型:
class SlovnikWord
{
public int Id { get; set; } = -1;
public string Title { get; set; }
public string Description { get; set; }
public List<Word> Forms { get; set; }
...
}
And the model for Word
is as follows Word
的模型如下
class Word
{
public int Id { get; set; } = -1;
public string Title { get; set; }
public string Description { get; set; }
...
}
I need to create a list of all the Forms
from all the original list of SlovnikWords
, here's what I came up with: 我需要从
SlovnikWords
所有原始列表中创建所有Forms
的列表,这是我SlovnikWords
的:
var q = SlovnikData.Select(x => x.Forms);
This unfortunately creates an array of arrays, where as I only need one dimensional array of Forms
without the outer one, ie a compound of x.Forms
, please help. 不幸的是,这创建了一个数组数组,由于我只需要一个
Forms
一维数组而没有外部数组,即x.Forms
的复合,请提供帮助。
应该这样做:
var q = SlovnikData.SelectMany(x => x.Forms);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.