开发者

NameValueCollection doesn't actually do anything with its IEqualityComparer?

开发者 https://www.devze.com 2023-01-03 20:53 出处:网络
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 collec开发者_运维百科tion by

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 collec开发者_运维百科tion 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.).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消