Advertisement
vencinachev

StudentHash

Sep 12th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. class Student
  2.     {
  3.         private string name;
  4.         private int age;
  5.  
  6.  
  7.         public Student(string name, int age)
  8.         {
  9.             this.name = name;
  10.             this.age = age;
  11.         }
  12.  
  13.         public override bool Equals(object obj)
  14.         {
  15.             Student other = obj as Student;
  16.             return this.name == other.name && this.age == other.age;
  17.         }
  18.  
  19.         public override int GetHashCode()
  20.         {
  21.             return this.name.GetHashCode() ^ this.age.GetHashCode();
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement