English 中文(简体)
Gethashcode()功能
原标题:Gethashcode() function

Why aren t C1 and c2 have the same hashcode ? the code doesn t get to "Same".... ( i=0 in both classes)

class myclass
{
    public static int i;

    static void Main()
    {
        myclass c1 = new myclass();
        myclass c2 = new myclass();

        if (c1.GetHashCode() == c2.GetHashCode())
            Console.Write("Same");

    }
}
最佳回答

)的缺席执行以该参考文献为基础,而不是以标的领域为基础。

如果你想照此办理,你必须超越)条,因此,它基于你的领域(然后,你应记住的是超越<条码>。

问题回答

由于你重创了同一类的不同事例>。 每一班级都有自己的散列代码,而散列代码则用于在你的节目记忆中识别物体,即使两者都具有相同的外地价值。

但是,如果你这样做的话,那就写了“Same”,因为你只是再造两个与同一物体有关的变量(即你通过c2:

    myclass c1 = new myclass();
    myclass c2 = c1;

    if (c1.GetHashCode() == c2.GetHashCode())
        Console.Write("Same");

当然,我不认为这是你期望实现的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签