Code inspection: Struct with default equality members is used for comparison (non-private accessibility)

Last modified: 08 August 2024

This inspection reports struct types that do not have Equals/GetHashCode overrides, and that have usages in the current solution. Usages of such structs can negatively affect performance.

In the example below, MyPoint struct is used as a key in the Points dictionary. This means that usages of Points will implicitly result in calling the suboptimal default implementations of Equals/GetHashCode:

To fix this performance issue, you can generate Equals/GetHashCode implementations in your struct via quick-fixes or turn your struct declaration into record struct, which will force the C# compiler to generate good Equals/GetHashCode implementations for you.