For a bit of code I am writing, I have a method which checks a new object for similar properties with all existing objects.
This method returns a Dictionary<int, List<int>>. They key is the unique object ID, and the List contains the properties which are similar with the new object. (Constant.Name, Constant.StartDt, etc).
Now, there are several different types of matches which cannot occur. I need a way to compare the various combinations of matches to what is in these lists, and I need to be able to know which match has been matched.
Therefore, I was thinking of creating a List for each match, and comparing each list with the returned property list. However, I know I have done something similar before in Java and it had a flaw – it matched by order…I just need to know if each list CONTAINS these items.
so, two questions:
- Is this the best way to find the matches?
- If so, what is your suggested method of doing so? Loop through them? Or is there something built in to C# and I am not aware?
You could use the LINQ Intersect method:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.intersect.aspx