Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以使用LINQ查询两个列表以填充单个列表吗_C#_Linq - Fatal编程技术网

C# 我可以使用LINQ查询两个列表以填充单个列表吗

C# 我可以使用LINQ查询两个列表以填充单个列表吗,c#,linq,C#,Linq,我有以下C#类课程: 我想做的是创建: List<WebWordForm> = a. << A LINQ statement if possible List=a 您可以使用和的组合来执行以下操作: List<WebWordForm> results = a.SelectMany(definition => //each definition will generate many WebWordForms definition.

我有以下C#类课程:

我想做的是创建:

List<WebWordForm> = a. << A LINQ statement if possible

List=a 您可以使用和的组合来执行以下操作:

List<WebWordForm> results =
    a.SelectMany(definition => //each definition will generate many WebWordForms
        definition.Def
        .Select(def => new WebWordForm //each def will generate one WebWordForm
        {
            definition = def.definition,
            partOfSpeech = definition.partOfSpeech,
            synonyms = def.synonyms
        }))
    .ToList();
列出结果=
a、 SelectMany(definition=>//每个定义将生成许多WebWordForms
定义.Def
.Select(def=>newWebWordForm//每个def将生成一个WebWordForm
{
definition=def.definition,
partOfSpeech=定义。partOfSpeech,
同义词
}))
.ToList();

您可以使用和的组合来执行以下操作:

List<WebWordForm> results =
    a.SelectMany(definition => //each definition will generate many WebWordForms
        definition.Def
        .Select(def => new WebWordForm //each def will generate one WebWordForm
        {
            definition = def.definition,
            partOfSpeech = definition.partOfSpeech,
            synonyms = def.synonyms
        }))
    .ToList();
列出结果=
a、 SelectMany(definition=>//每个定义将生成许多WebWordForms
定义.Def
.Select(def=>newWebWordForm//每个def将生成一个WebWordForm
{
definition=def.definition,
partOfSpeech=定义。partOfSpeech,
同义词
}))
.ToList();

使用
选择多个
linq扩展,您可以这样做

var result = a.SelectMany(x=> 
               {
                     x.Def.Select(s=> new WebWordForm()
                           {
                               partOfSpeech = x.partOfSpeech,
                               definition  = s.definition,
                               synonyms = s.synonyms,
                              // other properties
                           }).ToList()
                })
               .ToList() ;

使用
SelectMany
linq扩展,您可以做到这一点

var result = a.SelectMany(x=> 
               {
                     x.Def.Select(s=> new WebWordForm()
                           {
                               partOfSpeech = x.partOfSpeech,
                               definition  = s.definition,
                               synonyms = s.synonyms,
                              // other properties
                           }).ToList()
                })
               .ToList() ;
试试这个

            List<Definition> a = new List<Definition>();
            List<WebWordForm> words = a.AsEnumerable().Select(x => x.Def.Select(y => new WebWordForm() {
                partOfSpeech = x.partOfSpeech,
                definition = y.definition,
                synonyms = y.synonyms
            }).ToList()
            ).FirstOrDefault();
List a=新列表();
列出单词=a.AsEnumerable().Select(x=>x.Def.Select(y=>newWebWordForm()){
partOfSpeech=x。partOfSpeech,
定义=y.definition,
同义词
})托利斯先生()
).FirstOrDefault();
试试这个

            List<Definition> a = new List<Definition>();
            List<WebWordForm> words = a.AsEnumerable().Select(x => x.Def.Select(y => new WebWordForm() {
                partOfSpeech = x.partOfSpeech,
                definition = y.definition,
                synonyms = y.synonyms
            }).ToList()
            ).FirstOrDefault();
List a=新列表();
列出单词=a.AsEnumerable().Select(x=>x.Def.Select(y=>newWebWordForm()){
partOfSpeech=x。partOfSpeech,
定义=y.definition,
同义词
})托利斯先生()
).FirstOrDefault();

typeOf
hasTypes
derivation
示例
?@YacoubMassad的值将保留为空
typeOf
hasTypes
、和
示例
?@YacoubMassad的值将保留为空