JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Code inspection: Usage of default struct equality

Last modified: 21 August 2024

This inspection reports usages of struct types that do not have Equals/GetHashCode overrides. Usages of such structs can negatively affect performance.

In the example below, Points dictionary uses MyPoint struct as a key. 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.