views:

22

answers:

1

I am looking at System.Collections.Specialized.NameValueCollection and it takes an IEqualityComparer, which is good news if someone like me wanted to sort the items in the collection by, say, something like the alphabetical order of the keys.

But, on a closer look in Reflector, I don't see the NVC class actually using the IEqualityComparer anywhere. Is my observation correct? As in, I don't see any use for an IEqualityComparer in an enumerable entity other than to re-arrange its constituent items on some cardinal order. And I do not see a method on NVC that looks like it might want to do something of that sort (Sort, Arrange, OrderBy, Aggregate, etc.).

A: 

NameValueCollection uses a Hashtable internally to store the values. The Hashtable uses the IEqualityComparer to hash and compare keys for equality.

Also note that IEqualityComparer doesn't do any ordering, it only compares for equality (as the name implies) so it's not useful if you want to sort values/keys.

Dean Harding