NameValueCollection 实际上并没有对其 IEqualityComparer 执行任何操作?
我正在查看 System.Collections.Specialized.NameValueCollection ,它需要一个 IEqualityComparer ,如果像我这样的人想要对集合中的项目进行排序,比如,类似于按键的字母顺序。
但是,仔细观察 Reflector
,我没有看到 NVC
类在任何地方实际使用 IEqualityComparer
。我的观察正确吗?例如,除了按某些基本顺序重新排列其组成项之外,我认为可枚举实体中的 IEqualityComparer 没有任何用处。而且我在 NVC
上没有看到任何看起来可能想要执行此类操作的方法(Sort
、Arrange
、排序依据
、聚合
等)。
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.).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NameValueCollection
使用哈希表 在内部存储值。Hashtable
使用IEqualityComparer
来散列和比较键是否相等。另请注意,
IEqualityComparer
不执行任何排序,它仅比较相等性(顾名思义),因此如果您想要对值/键进行排序,则它没有用。NameValueCollection
uses a Hashtable internally to store the values. TheHashtable
uses theIEqualityComparer
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.