Created
August 11, 2019 16:19
-
-
Save RolandPheasant/e26ad64c16cdec31c813abfe0a907d64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person : IEquatable<Person> | |
{ | |
public string UID { get; set; } = Guid.NewGuid().ToString(); | |
public string Name { get; set; } | |
public string Surname { get; set; } | |
public int Age { get; set; } | |
public bool Equals(Person other) | |
{ | |
if (ReferenceEquals(null, other)) return false; | |
if (ReferenceEquals(this, other)) return true; | |
return string.Equals(Name, other.Name) && string.Equals(Surname, other.Surname) && Age == other.Age; | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (ReferenceEquals(this, obj)) return true; | |
if (obj.GetType() != this.GetType()) return false; | |
return Equals((Person) obj); | |
} | |
public override int GetHashCode() | |
{ | |
unchecked | |
{ | |
var hashCode = (Name != null ? Name.GetHashCode() : 0); | |
hashCode = (hashCode * 397) ^ (Surname != null ? Surname.GetHashCode() : 0); | |
hashCode = (hashCode * 397) ^ Age; | |
return hashCode; | |
} | |
} | |
public static bool operator ==(Person left, Person right) | |
{ | |
return Equals(left, right); | |
} | |
public static bool operator !=(Person left, Person right) | |
{ | |
return !Equals(left, right); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment