Added implementation of Equal() and GetHashCode()

This commit is contained in:
MarcUs7i 2025-01-20 20:48:57 +01:00
parent 8b23b2bd20
commit cb34bde971

View file

@ -52,14 +52,20 @@ public sealed class BusinessCard
/// </summary>
/// <param name="obj">Other object to compare to</param>
/// <returns>True if the objects are equal; false otherwise</returns>
// TODO
public override bool Equals(object? obj)
=> false;
public override bool Equals(object? obj)
{
if (obj is not BusinessCard other)
{
return false;
}
return FirstName == other.FirstName && LastName == other.LastName;
}
/// <summary>
/// Calculates the hash code for this object
/// </summary>
/// <returns>Numeric hash code</returns>
// TODO
public override int GetHashCode() => -1;
// Uses XOR to combine the bits of each hash code
public override int GetHashCode() => FirstName.GetHashCode() ^ LastName.GetHashCode();
}