Custom Class used as key in Dictionary but key not found

前端 未结 4 721
忘了有多久
忘了有多久 2020-12-19 02:03

I have a class, show below, which is used as a key in a Dictionary I\'m having issues when trying to find any key within this diction

4条回答
  •  感动是毒
    2020-12-19 02:31

    I had this problem, turns out the dictionary was comparing referances for my key, not the values in the object.

    I was using a custom Point class as keys. I overrode the ToString() and the GetHashCode() methods and viola, key lookup worked fine.

提交回复
热议问题