I am working with two list that contain many properties. I am attempting to loop through the lists and return a comparison of the two objects in the form of a count (int). The count is defined as the number of properties that are equal.
Below is an example of this:
class Object{
public string prop1 {get;set;} //x5 Avg Length (20-30 Char)
public double prop2 {get;set;} //x3
}
private int CompareProps(Object a, Object b)
{
int matchedElements = 0;
if (a.Prop1 == b.Pro1)
matchedElements++; ;
if (a.Prop2 == b.Prop2)
matchedElements++;
// More Property Comparisons...
return matchedElements;
}
///Loops in another method with two Lists of Object, where each list.count = 300
List1 = getList1Objects();//300 Objects
List2 = getList2Objects();//300 Objects
int l1 = List1.Count;
int l2 = List2.Count;
Parallel.For(0, l1, i =>
{
for (int j = 0; j < l2; j++)
{
int k = CompareProps(List1[i], List2[j]);
}
});
This is very inefficient though. Is there are better way to do this in C#? The properties can be strings, doubles, etc.
Thanks!
