Started with overriding concepts and I override the methods Equals
and GetHashCode
.
Primarily I came up with this \"very simple code\":
To summarise what was discussed in the comments:
Hashing is designed to provide a value that doesn't change for a given object, no matter what happens to it - hence it's best to depend only on readonly fields in your GetHashCode method.
Firstly, I would suggest making the name
and lname
field readonly, because they probably don't change in your usage scenario.
As for age
, this is something that changes regularly, so probably best to store a DateTime
for date of birth, which never changes. Then you can make that readonly too.