What is an appropriate `GetHashCode()` algorithm for a 2D point struct (avoiding clashes)

前端 未结 5 2053
长发绾君心
长发绾君心 2020-12-20 11:31

Consider the following code:

struct Vec2 : IEquatable
{
    double X,Y;

    public bool Equals(Vec2 other)
    {
        return X.Equals(other.X         


        
5条回答
  •  情书的邮戳
    2020-12-20 12:13

    If size of your hash code is lesser than size of your struct, then clashes are inevitable anyways.

提交回复
热议问题