.NET: Is Type.GetHashCode guaranteed to be unique?

前端 未结 3 697
离开以前
离开以前 2021-01-17 17:56

I have someone using Type.GetHashCode as if it were a primary key. I think this is a horrible idea but I wanted to know if there was some sort of documented special case tha

3条回答
  •  无人及你
    2021-01-17 18:06

    The goal of producing a hash code for an object is to be as unique as possible given the type of data to avoid collisions in the table. But, it's absolutely not guaranteed. Many hash table implementations chain (an array list) off of each hash code bucket to deal with collisions.

提交回复
热议问题