I’m wondering if my method below of comparing an array of strings (or any simple type really) has any performance repercussions.
bool AreValuesEqual(List<string> oldFieldValue, List<string> newFieldValue)
{
if (oldFieldValue.Count != newFieldValue.Count)
return false;
var list1 = oldFieldValue;
list1.AddRange(newFieldValue);
var list2 = list1.Distinct();
return list2.Count() == newFieldIds.Count;
}
I don’t know how intensive Distinct() will be for this, but I think it shouldn’t be too much compared to another loop.
Edit – Sorry, should have provided more background info. Couple things:
-There will be no duplicates in the parameter arrays.
-I’m not really concerned about order, I just want to know if the values in one array is the same as the other array. If the other array has a different value, return false.
I don’t think there’s a significant performance issue with your code. However, what bothers me a little is that you’re modifying list1 as a side-effect of doing the comparison.
Will the following work better?
A similar question was posted at Compare two Lists for differences.