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