Search code examples
c#.netguidhashcode.net-4.6.2

Can same GUID produce different hash codes?


Given same GUID Object.GetHashCode produces different hash codes but Object.Equals shows that same GUID equals.

The whole GUID:

enter image description here

Not same hash code:

enter image description here

Equals == true:

enter image description here

And, obviously, both are System.Guid:

enter image description here

Even when it's the same GUID, they're different values as they are deserialized from two sources.

Is this the expected behavior?


Solution

  • Your test is incorrect. In the final part where you're comparing the .GetType().FullName, you are looking at the .Id, but that is not what you are comparing above that.

    So: the problem is in whatever the type is that has a .Id, the thing that is in tags and existingTags. Look at the Equals and GetHashCode of that.