Added implementation of Equal() and GetHashCode()
This commit is contained in:
parent
8b23b2bd20
commit
cb34bde971
1 changed files with 11 additions and 5 deletions
|
|
@ -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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue