Search code examples
c#.netgethashcode

Does hash code is being stored in SyncBlockIndex/SyncBlock


Every object in .net has headers (SyncBlockIndex and MethodTablePointer), and when you call GetHashCode() the result could be saved in SyncBlockIndex if there is no linked SyncBlock to this object, or in SyncBlock if so.

When we don't override GetHashCode method hash code is the save during object existence, but how hash code will be storing in case we return dynamic hash code (dependent on object's state)?

I know that hash code should be the same during object existence, the purpose of question is to understand how hash code is being stored in SyncBlockIndex or in SyncBlock.


Solution

  • how hash code will be storing in case we return dynamic hash code (dependent on object's state)?

    If the hash code is dynamically computed via an override of GetHashCode is is not stored anywhere...

    The usage of SyncBlockIndex as the "default" hash code for an object is an implementation detail and should not be relied upon for anything outside of the framework.