I have a double foreach loop and want to speed it up by making it one loop instead of two.
The idea is that it takes one element from the dictionary and compares it against all elements in the dictionary
foreach (KeyValuePair<Int64, string> kvp in originCounts)
{
foreach (KeyValuePair<Int64, string> testkvp in originCounts)
{
//Run Comparison on testkvp ad kvp
}
}
I want to turn this into one loop, any suggestions?
You can use
Enumerable.Allto check if all elements are the same:It seems that this is what you actually want.
I’ve just picked out a field of your class in the duplicate question that sounds as a reasonable identifier.
Edit: According to your comment you want to determine if any of the objects’ fields is different to the same field of another object.