Guid & GetHashCode uniqueness

后端 未结 5 1314
情话喂你
情话喂你 2020-12-06 04:37

Given the following key:

int key = Guid.NewGuid().GetHashCode();

Is this key unique as the uniqueness of Guid?

5条回答
  •  青春惊慌失措
    2020-12-06 04:43

    GetHashCode() returns an integer - it cannot be as unique as a Guid, so no - there might be collisions and uniqueness is not guaranteed.

    The point of a hash code is that it should distribute evenly across the hash range so that collisions should be generally rare, you always have a chance of collision though and have to accommodate for that.

提交回复
热议问题