C# 我可以使用LINQ查询两个列表以填充单个列表吗
我有以下C#类课程: 我想做的是创建: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.
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的值将保留为空