C# 交叉字典<;字符串,列表<;动画>&燃气轮机;关于动画类的一个性质

C# 交叉字典<;字符串,列表<;动画>&燃气轮机;关于动画类的一个性质,c#,list,dictionary,array-intersect,C#,List,Dictionary,Array Intersect,我有一个这样的物体 public class Anime { public Guid Id {get; set;} public DateTime? CreatedOn {get; set;} } 然后我有一本字典,上面有 Dictionary<string, List<Anime>> myLists = new Dictionary<string, List<Anime>>(); Dictionary mylist=new

我有一个这样的物体

public class Anime 
{
    public Guid Id {get; set;}
    public DateTime? CreatedOn {get; set;}

}
然后我有一本字典,上面有

Dictionary<string, List<Anime>> myLists = new Dictionary<string, List<Anime>>();
Dictionary mylist=newdictionary();
我正在交叉所有列表,但我只想在动画ID上进行交叉,但仍然会得到
列表
,不确定如何具体强制它在ID上进行交叉。以下是我的:

myResult.AddRange(myLists.Values.Aggregate(new HashSet<Anime>(myLists.First().Value.ToList()), (h, e) =>
                        {
                            h.IntersectWith(e);
                            return h;
                        }));
myResult.AddRange(myLists.Values.Aggregate)(新哈希集(myLists.First().Value.ToList()),(h,e)=>
{
h、 与(e)相交;
返回h;
}));

有没有办法告诉它在ID属性上相交,但仍然以动画列表的形式获得结果?(
myResult
是一个
List
)。

我认为列表不能包含多个具有相同Id的动画。 这应该起作用:

var result = myLists.Values.SelectMany(p => p)
                .GroupBy(a => a.Id)
                .Where(g => g.Count() == myLists.Values.Count)
                .Select(g => g.First());

属性上的intersect的等效项是
join

myResult.AddRange(myLists.Values.Aggregate((a, l) => a.Join(l, am => am.Id, lm => lm.Id, (am, lm) => am).ToList()));

结果你想要什么?字典中多次出现的动画列表?或者出现在字典中每个列表中的动画列表?所有列表中都具有相同ID的动画列表。所以如果我有n个列表,ID 5应该在所有列表中,那么我想把这部动画添加到我的结果列表中。