I want to compare the contents of two Dictionary instances regardless of the order of the items they contain. SequenceEquals
I don't know if there is an existing method but you could use the following (null checking of args omitted for brevity)
public static bool DictionaryEquals(
this Dictionary left,
Dictionary right ) {
var comp = EqualityComparer.Default;
if ( left.Count != right.Count ) {
return false;
}
foreach ( var pair in left ) {
TValue value;
if ( !right.TryGetValue(pair.Key, out value)
|| !comp.Equals(pair.Value, value) ) {
return false;
}
}
return true;
}
It would be best to add an overload to allow customization of the EqualityComparer.