Compare two int lists
I have an object that looks like this:
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; }
}
}
I get a list of of these objects that looks something like this:
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"));
Then I have several lists of integers like so:
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);
What I'd like to do is to be able to check these integers lists against
the TestObject list and extract TestObjects that are equal. In other
words, in this example list1 would find a hit in the object at position 0,
list4 would find a hit in position 2, there is no hit for list3 as there
is only a partial in position 4 and there is no hit for list2 as it does
not exist.
I thought first that it could be done with "Except." So, if there is
nothing between the listN and listTest at n position then that is a hit??
The thing is how to compare the listN to the list in the object at
position N in listTest??
No comments:
Post a Comment