【发布时间】:2015-07-02 20:21:29
【问题描述】:
我有一个班级组和一个列表
我包括dotnetFiddle
class Group
{
public List<int> manyID;
public int otherID;
}
List<Group> allGroup = new List<Group>();
Group g;
g = new Group();
g.manyID = new List<int>(new int[] { 1, 3 } );
g.otherID = 1;
allGroup.Add(g);
g = new Group();
g.manyID = new List<int>(new int[] { 0, 2, 4 } );
g.otherID = 2;
allGroup.Add(g);
g = new Group();
g.manyID = new List<int>(new int[] { 2, 3 } );
g.otherID = 3;
allGroup.Add(g);
我想过滤子组列表中出现的 manyID 中具有任何 ID 的所有组。
Group subGroup = new Group();
subGroup.manyID = new List<int>(new int[] { 0, 1 } );
对于单个 ID,我知道该怎么做。这只会带来第一组。
List<Group> filterGroup = allGroup
.Where( a => subGroup.manyID.Contains( a.otherID))
.ToList();
清单是什么?这应该带来前 2 组。
List<Group> filterGroup = allGroup
.Where( a => subGroup.manyID.Contains( **a.manyID**))
.ToList();
【问题讨论】:
-
你需要的是 intersect 方法,检查这个stackoverflow.com/questions/10667675/…