c# - Are Hash Codes for structs consistent in the .NET Framework? -
this question has answer here:
do structs built .net framework return same hash code if contents equal? thinking system.drawing.color , size
yes.
correctly implemented gethashcode returns same value items considered equal. existing struct in .net indeed implement such functionality meet expectation.
notes
- if hash codes equal not mean objects equal.
- there no requirement hash code same "value" stay same outside single execution of application. unlikely simple types
int32,size, 1 should not rely on hash code. if need consistent value - implement , use own methods.
you can more detailed discussion eric lippert's guidelines , rules gethashcode.
Comments
Post a Comment