本文介绍了与嵌套集合不同.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下设置:
I''ve got the following setup:
class A
{
ObservableCollection Bs {get;set;}
}
class B
{
string Title {get; set;}
ObservableCollection<C> Cs {get;set;}
}
class C
{
string Title {get;set;}
}
我正在尝试获取整个A中唯一标题的列表.
到目前为止,我已经
I''m trying to get a list of unique Title''s in the entire of A.
So far I''ve got
var bTitles = A.Bs.Select(f=> f.Title).Distinct();
var cTitles = A.Bs.Select(f=> f.Cs).Select(h=> h.Select(g=> g.Title));
return bTitles.Union(cTitles);
但这是不对的,我无法展平" cTitle,至少我认为那是我错了.
But that''s not right, I can''t ''flatten'' cTitles, at least I think that''s what I''ve got wrong.
推荐答案
var titles = A.Bs
.Select(b => b.Title)
.Union(A.Bs.SelectMany(b => b.Cs, (b, c) => c.Title))
.Distinct();
这篇关于与嵌套集合不同.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!