Use custom object as Dictionary Key

后端 未结 3 1266
生来不讨喜
生来不讨喜 2020-12-03 09:49

I want to use a custom object as a Dictionary key, mainly, I have something like this: (I can\'t use .net 4.0 so I don\'t have tuples)

class Tuple

        
3条回答
  •  半阙折子戏
    2020-12-03 10:43

    You need to override GetHashCode when you override Equals method. More explanation can be found here:

    Why is it important to override GetHashCode when Equals method is overridden?

提交回复
热议问题