Non-readonly fields referenced in GetHashCode()

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)