Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. public class Student : IEquatable<Student>
  2. {
  3. public string Name { get; }
  4. public decimal Gpa { get; }
  5. public Student(string Name, decimal Gpa)
  6. {
  7. this.Name = Name;
  8. this.Gpa = Gpa;
  9. }
  10. public bool Equals(Student other) // for IEquatable<Student>
  11. {
  12. return other != null && Equals(Name, other.Name) && Equals(Gpa, other.Gpa);
  13. }
  14. public override bool Equals(object other)
  15. {
  16. return this.Equals(other as Student);
  17. }
  18. public override int GetHashCode()
  19. {
  20. return (Name?.GetHashCode()*17 + Gpa?.GetHashCode()).GetValueOrDefault();
  21. }
  22. public Student With(string Name = this.Name, decimal Gpa = this.Gpa) => new Student(Name, Gpa);
  23. public void Deconstruct(out string Name, out decimal Gpa)
  24. {
  25. Name = self.Name;
  26. Gpa = self.Gpa;
  27. }
  28. }
Add Comment
Please, Sign In to add comment