在arraylist中使用GetHashCode [英] the use of GetHashCode in arraylist

查看:80
本文介绍了在arraylist中使用GetHashCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 你能告诉我这是什么意思,最后一行返回什么:

Hi could you tell me what does it mean and what does the last line return:

ArrayList p = new ArrayList;<br />
 p.GetHashCode();

推荐答案

来自MSDN:

哈希码是一个数值,用于在相等性测试期间标识对象.它也可以用作集合中对象的索引.

GetHashCode方法适用于哈希算法和数据结构(例如哈希表).


我想总结一下!
From MSDN:

A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection.

The GetHashCode method is suitable for use in hashing algorithms and data structures such as a hash table.


I think that about sums it up!


首先,不需要使用ArrayList,因为在.NET Framework 2.0中引入泛型已使它过时.使用System.Collections.Generic.List.现在,确实需要object.GetHashCode将数据元素存储在基于哈希的容器中:System.Generic.Collections.DictionarySystem.Generic.Collections.SortedDictionarySystem.Generic.Collections.SortedList. Key类型的哈希码很重要,应以提供良好"哈希属性的方式编写,以帮助优化集合中的搜索速度.

这种搜索和数据结构的机制基于 backets ,在此进行了解释: http://en .wikipedia.org/wiki/Hash_table [ ^ ] .

-SA
First, there is not need to use ArrayList since it was rendered obsolete by introducing of generics in .NET Framework 2.0. Use System.Collections.Generic.List. Now, object.GetHashCode is really needed to store data elements in hash-based containers: System.Generic.Collections.Dictionary, System.Generic.Collections.SortedDictionary, System.Generic.Collections.SortedList. The hash code for the Key type is important and should be written the way to provide "good" hashing properties helping to optimize the search speed in the collection.

The mechanism of such search and data structure is based on backets, which is explained here: http://en.wikipedia.org/wiki/Hash_table[^].

—SA


^ ]和msdn ^ ].
Some good information on the GetHashCode() method at a blog[^] and on the msdn link[^].


这篇关于在arraylist中使用GetHashCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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