Skip to content

Collections like Lists are cannot be used with HashCode.Combine(collection); #10908

Open
@norcino

Description

@norcino

Type of issue

Missing information

Description

I spent a good deal of time trying to understand why my Distinct operations were not working for a newly created Type.
It turns out that the HashCode.Combine(collection); does not work, it works fine when the instances passed in are not collections, but the documentation doesn't say that clearly.
In my opinion there should be a type check in the method itself as this makes the code very dangerous as only at runtime the issue can be discovered.
I found it just because I was testing most of the equality features around my new type.

I'd be happy to know if I am missing something

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.hashcode.combine?view=net-8.0#system-hashcode-combine-1(-0)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/HashCode.xml

Document Version Independent Id

4b23ab47-87c7-32b1-a0ca-9c13d5ec93e5

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions