GetHashCode override of object containing generic array

前端 未结 9 1680
情歌与酒
情歌与酒 2020-12-04 05:35

I have a class that contains the following two properties:

public int Id      { get; private set; }
public T[] Values  { get; private set; }
<
9条回答
  •  温柔的废话
    2020-12-04 05:47

    I would do it this way:

    long result = Id.GetHashCode();
    foreach(T val in Values)
        result ^= val.GetHashCode();
    return result;
    

提交回复
热议问题