NameValueCollection 实际上并没有对其 IEqualityComparer 执行任何操作?

发布于 2024-09-06 01:14:54 字数 419 浏览 3 评论 0原文

我正在查看 System.Collections.Specialized.NameValueCollection ,它需要一个 IEqualityComparer ,如果像我这样的人想要对集合中的项目进行排序,比如,类似于按键的字母顺序。

但是,仔细观察 Reflector,我没有看到 NVC 类在任何地方实际使用 IEqualityComparer。我的观察正确吗?例如,除了按某些基本顺序重新排列其组成项之外,我认为可枚举实体中的 IEqualityComparer 没有任何用处。而且我在 NVC 上没有看到任何看起来可能想要执行此类操作的方法(SortArrange排序依据聚合等)。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

NameValueCollection 使用哈希表 在内部存储值。 Hashtable 使用 IEqualityComparer 来散列和比较键是否相等。

另请注意,IEqualityComparer 不执行任何排序,它仅比较相等性(顾名思义),因此如果您想要对值/键进行排序,则它没有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文