Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The GetHashCode implementation of the Thickness struct is broken for uniform length. #8789

Open
davidskula opened this issue Feb 8, 2024 · 1 comment · May be fixed by #8822
Open

The GetHashCode implementation of the Thickness struct is broken for uniform length. #8789

davidskula opened this issue Feb 8, 2024 · 1 comment · May be fixed by #8822
Labels
🚧 work in progress Investigate Requires further investigation by the WPF team.

Comments

@davidskula
Copy link

Description

For any uniform length instance of Thickness struct GetHashCode returns zero.

Reproduction Steps

var h1 = new Thickness(5).GetHashCode();
var h2 = new Thickness(10).GetHashCode();

Expected behavior

h1 and h2 should have different values

Actual behavior

h1 and h2 have the same value

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

@singhashish-wpf singhashish-wpf added the Investigate Requires further investigation by the WPF team. label Feb 9, 2024
@lindexi
Copy link
Contributor

lindexi commented Feb 18, 2024

The reason is:

public override int GetHashCode()
{
return _Left.GetHashCode() ^ _Top.GetHashCode() ^ _Right.GetHashCode() ^ _Bottom.GetHashCode();
}

The uniform length means that the _left == _Top == _Right == _Bottom. And the same value call the GetHashCode will return the same result. And the two same value call the ^ will return zero.

I'm not sure I can change its behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚧 work in progress Investigate Requires further investigation by the WPF team.
Projects
None yet
3 participants