相关疑难解决方法(0)

为什么System.String对象不能缓存其哈希代码?

浏览string.GetHashCode使用Reflector的源代码会显示以下内容(对于mscorlib.dll版本4.0):

public override unsafe int GetHashCode()
{
    fixed (char* str = ((char*) this))
    {
        char* chPtr = str;
        int num = 0x15051505;
        int num2 = num;
        int* numPtr = (int*) chPtr;
        for (int i = this.Length; i > 0; i -= 4)
        {
            num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0];
            if (i <= 2)
            {
                break;
            }
            num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ numPtr[1]; …
Run Code Online (Sandbox Code Playgroud)

.net string hashcode immutability gethashcode

39
推荐指数
3
解决办法
2829
查看次数

标签 统计

.net ×1

gethashcode ×1

hashcode ×1

immutability ×1

string ×1