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 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