Last active
July 31, 2016 20:14
-
-
Save JohanLarsson/f9b1b263730792837f8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
{ | |
public Person(string name, int age) | |
{ | |
this.Name = name; | |
this.Age = age; | |
} | |
public string Name { get; private set; } | |
public int Age { get; private set; } | |
protected bool Equals(Person other) | |
{ | |
return string.Equals(this.Name, other.Name) && this.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 | |
{ | |
return (this.Name.GetHashCode() * 397) ^ this.Age; | |
} | |
} | |
public static bool operator ==(Person left, Person right) | |
{ | |
return Equals(left, right); | |
} | |
public static bool operator !=(Person left, Person right) | |
{ | |
return !Equals(left, right); | |
} | |
} |
This file contains hidden or 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
type Person = { Name : string ; Age : int } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment