All rules
IDE0070Language rules (expression-level preferences)
Use System.HashCode.Combine
Use System.HashCode.Combine
Microsoft docsDescription
This rule recommends the use of the System.HashCode.Combine method to compute a hash code instead of using custom hash code computation logic.
Example
class B
{
public override int GetHashCode() => 0;
}
class C : B
{
int j;
// Code with violations
public override int GetHashCode()
{
// IDE0070: GetHashCode can be simplified.
var hashCode = 339610899;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + j.GetHashCode();
return hashCode;
}
// Fixed code
public override int GetHashCode()
{
return System.HashCode.Combine(base.GetHashCode(), j);
}
}Configurable options
Vote for the value each option should take in the generated .editorconfig.
dotnet_prefer_system_hash_code default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0