Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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