.NET对象哈希码该怎么办? [英] What would I do with a .NET object hashcode?

查看:57
本文介绍了.NET对象哈希码该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#中的对象具有四个方法-{ Equals GetType ToString GetHashCode }.br>某人可以对哈希码做什么样的有用的事情?

An object in C# has four methods - {Equals, GetType, ToString, GetHashCode}.
What sort of useful thing could someone do with the hash-code?

推荐答案

某人可以对哈希码进行哪些有用的事情?

What sort of useful thing could someone do with the hashcode?

快速找到可能个相等的对象.

Quickly find potentially equal objects.

尤其是,这种方法通常由 (用于密钥)和 HashSet< T> .

In particular, this method is usually used by types such as Dictionary<TKey, TValue> (for the keys) and HashSet<T>.

您应该假定具有相同哈希码的对象是相等的.参见 Eric Lippert的博客文章获取更多信息,而 Wikipedia哈希表页上的哈希码的使用.

You should not assume that objects with equal hash codes are equal, however. See Eric Lippert's blog post for more information, and the Wikipedia hash table page for a more general discussion on the uses of hash codes.

这篇关于.NET对象哈希码该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆