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>
|
/// </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();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue