我可以依靠GetHash code的值()是一致的? [英] Can I depend on the values of GetHashCode() to be consistent?

查看:70
本文介绍了我可以依靠GetHash code的值()是一致的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是正在使用GetHash code()保证是一致的假设相同的字符串值的返回值? (C#/ ASP.NET)

Is the return value of GetHashCode() guaranteed to be consistent assuming the same string value is being used? (C#/ASP.NET)

我上传了我的code到服务器今天让我吃惊,我不得不重新索引一些数据,因为我的服务器(WIN2008 64位)的相比,我的台式机返回不同的值。

I uploaded my code to a server today and to my surprise I had to reindex some data because my server (win2008 64-bit) was returning different values compared to my desktop computer.

推荐答案

如果我没有记错,GetHash code是一致给予相同的值,但它不保证在不同版本的框架一致

If I'm not mistaken, GetHashCode is consistent given the same value, but it is NOT guaranteed to be consistent across different versions of the framework.

从上String.GetHash code MSDN文档():

From the MSDN docs on String.GetHashCode():

GetHash code的行为取决于它的实现,这可能与公共语言运行库的一个版本到另一个改变。为什么这可能发生的一个原因是为了提高GetHash code的性能。

The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of GetHashCode.

这篇关于我可以依靠GetHash code的值()是一致的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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