Update GetHashCode implementations to use HashCode.Combine#52121
Update GetHashCode implementations to use HashCode.Combine#52121
Conversation
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
|
Tagging @T-Gro Do you want the F# samples here to use If not, I'll have Copilot reverse those changes. |
|
In F# the need to do custom HashCode is quite rare, using the .Combine helpers to put together two hash codes is OK here. |
BillWagner
left a comment
There was a problem hiding this comment.
With a couple suggestions, this is ready for final review
docs/fundamentals/runtime-libraries/system-object-gethashcode.md
Outdated
Show resolved
Hide resolved
docs/fundamentals/runtime-libraries/system-object-gethashcode.md
Outdated
Show resolved
Hide resolved
|
@copilot You need to add a basic That will fix the CI build. |
There was a problem hiding this comment.
Pull request overview
Updates GetHashCode guidance and snippets across the docs repo to use System.HashCode.Combine instead of older, collision-prone or allocation-heavy patterns.
Changes:
- Replaces tuple-based hashing and shift/XOR patterns in
GetHashCodeexamples withHashCode.Combine. - Updates
System.Object.GetHashCodearticle text to recommendHashCode.Combineand positions shift-and-wrap as a .NET Framework-era alternative. - Simplifies
PersonComparer.GetHashCodein C# and Visual Basic variance articles to useHashCode.Combine.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/visual-basic/programming-guide/concepts/covariance-contravariance/using-variance-in-interfaces-for-generic-collections.md | Updates VB comparer hash logic to HashCode.Combine. |
| docs/fundamentals/runtime-libraries/system-object-gethashcode.md | Updates guidance to recommend HashCode.Combine and reframes shift-and-wrap for .NET Framework. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/GetHashCode/vb/xor2.vb | Switches tuple hashing to HashCode.Combine and updates output note. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/GetHashCode/fsharp/xor2.fs | Switches tuple hashing to HashCode.Combine and updates output note. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/GetHashCode/csharp/xor2.cs | Switches tuple hashing to HashCode.Combine and updates output note. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/Equals/vb/equals2.vb | Updates Point/Point3D hash logic to HashCode.Combine. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/Equals/fsharp/equals2.fs | Updates Point/Point3D hash logic to HashCode.Combine. |
| docs/fundamentals/runtime-libraries/snippets/System/Object/Equals/csharp/equals2.cs | Updates Point/Point3D hash logic to HashCode.Combine. |
| docs/csharp/programming-guide/concepts/covariance-contravariance/using-variance-in-interfaces-for-generic-collections.md | Updates C# comparer hash logic to HashCode.Combine. |
...e/concepts/covariance-contravariance/using-variance-in-interfaces-for-generic-collections.md
Show resolved
Hide resolved
...e/concepts/covariance-contravariance/using-variance-in-interfaces-for-generic-collections.md
Show resolved
Hide resolved
docs/fundamentals/runtime-libraries/system-object-gethashcode.md
Outdated
Show resolved
Hide resolved
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
|
@copilot One more fsproj file to add in this folder: docs/fundamentals/runtime-libraries/snippets/System/Object/GetHashCode/fsharp/ |
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
HashCode.Combinexor2.cs(C#): ReplaceTuple.Create(x, y).GetHashCode()withHashCode.Combine(x, y)xor2.vb(VB): ReplaceTuple.Create(x, y).GetHashCode()withHashCode.Combine(x, y)xor2.fs(F#): Replace tuple hash withSystem.HashCode.Combine(x, y)system-object-gethashcode.md: Updated article text to recommendHashCode.Combine; removed version reference per reviewer suggestion; updated shift1 section to say "In .NET Framework" per reviewer suggestionequals2.cs(C#): UpdatePoint2andPoint3D.GetHashCodeto useHashCode.Combineequals2.vb(VB): UpdatePoint1andPoint3D.GetHashCodeto useHashCode.Combineequals2.fs(F#): UpdatePointandPoint3D.GetHashCodeto useHashCode.CombinePersonComparer.GetHashCodeto useHashCode.CombinePersonComparer.GetHashCodeto useHashCode.CombineProject.fsprojin F# Equals snippets folder to fix CI buildProject.fsprojin F# GetHashCode snippets folder to fix CI buildOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews