Skip to content

Instantly share code, notes, and snippets.

@JohanLarsson
Last active July 31, 2016 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohanLarsson/f9b1b263730792837f8c to your computer and use it in GitHub Desktop.
Save JohanLarsson/f9b1b263730792837f8c to your computer and use it in GitHub Desktop.
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);
}
}
type Person = { Name : string ; Age : int }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment