Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created October 21, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/ece8d14e1067402eb8027abf01b13b97 to your computer and use it in GitHub Desktop.
Save NMZivkovic/ece8d14e1067402eb8027abf01b13b97 to your computer and use it in GitHub Desktop.
public class Student : IEquatable<Student>
{
public string Name { get; }
public decimal Gpa { get; }
public Student(string Name, decimal Gpa)
{
this.Name = Name;
this.Gpa = Gpa;
}
public bool Equals(Student other) // for IEquatable<Student>
{
return other != null && Equals(Name, other.Name) && Equals(Gpa, other.Gpa);
}
public override bool Equals(object other)
{
return this.Equals(other as Student);
}
public override int GetHashCode()
{
return (Name?.GetHashCode()*17 + Gpa?.GetHashCode()).GetValueOrDefault();
}
public Student With(string Name = this.Name, decimal Gpa = this.Gpa) => new Student(Name, Gpa);
public void Deconstruct(out string Name, out decimal Gpa)
{
Name = self.Name;
Gpa = self.Gpa;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment