Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save es-repo/6e593fcda77576421761f84d6c48dfcd to your computer and use it in GitHub Desktop.

Select an option

Save es-repo/6e593fcda77576421761f84d6c48dfcd to your computer and use it in GitHub Desktop.
better-unit-test-in-c#-article-Box-Equals.cs
public sealed record Box
{
...
public bool Equals(Box? other)
{
if (other == null)
{
return false;
}
return IsOpen.Equals(other.IsOpen) &&
Size == other.Size &&
thingsInside.SequenceEqual(other.thingsInside);
}
public override int GetHashCode()
{
unchecked
{
int hash = 13;
hash = (hash * 7) + IsOpen.GetHashCode();
hash = (hash * 7) + Size.GetHashCode();
hash = thingsInside.Aggregate(hash, (acc, o) => (acc * 7) + o.GetHashCode());
return hash;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment