我有一个看起来像这样的对象:
public class TestObject {
private string name = string.Empty;
private List<int> ids;
public TestObject(List<int> ids, string name)
{
this.ids = ids;
this.name = name;
}
public string Name
{
get { return name; }
set { name = value; }
}
public List<int> Ids
{
get { return ids; }
set { ids = value; }
}
}
我得到了这些对象的列表,看起来像这样:
List<TestObject> listTest = new List<TestObject>();
listTest.Add(new TestObject((new int[] { 0, 1, 5 }).ToList(), "Test1"));
listTest.Add(new TestObject((new int[] { 10, 35, 15 }).ToList(), "Test2"));
listTest.Add(new TestObject((new int[] { 55 }).ToList(), "Test3"));
listTest.Add(new TestObject((new int[] { 44 }).ToList(), "Test4"));
listTest.Add(new TestObject((new int[] { 7, 17 }).ToList(), "Test5"));
然后我有几个整数列表,如下所示:
List<int> list1 = new List<int>();
list1.Add(0);
list1.Add(1);
list1.Add(5);
List<int> list2 = new List<int>();
list2.Add(4);
List<int> list3 = new List<int>();
list3.Add(7);
List<int> list4 = new List<int>();
list4.Add(55);
我想做的是能够对照 TestObject 列表检查这些整数列表并提取相等的 TestObjects。换句话说,在此示例中,list1 将在位置 0 的对象中找到命中,list4 将在位置 2 找到命中,list3 没有命中,因为位置 4 只有部分命中,而 list2 没有命中因为它不存在。
我首先认为它可以用“除了”来完成。那么,如果在 n 位置的 listN 和 listTest 之间没有任何内容,那么这就是命中?问题是如何将 listN 与 listTest 中位置 N 的对象中的列表进行比较?