Right way to implement GetHashCode for this struct

前端 未结 7 1876
庸人自扰
庸人自扰 2021-02-13 06:13

I want to use a date range (from one date to another date) as a key for a dictionary, so I wrote my own struct:

   struct DateRange
   {
      public DateTime St         


        
7条回答
  •  暖寄归人
    2021-02-13 06:57

    I would trust Microsoft's implementation of GetHashCode() at the tuples and use something like this without any stupid magic:

    public override int GetHashCode()
    {
        Tuple.Create(x, y).GetHashCode();
    }
    

提交回复
热议问题