예제 #1
0
 public virtual bool Equals(Student obj)
 {
     if (obj == null || GetType() != obj.GetType())
         return false;
     else if (Name == obj.Name && Gender == obj.Gender)
         return true;
     else
         return false;
 }
예제 #2
0
        static void Main(string[] args)
        {
            Student student1 = new Student() { Name = "Jimmy", Gender = "Male", Grade = 95 };
            Student student2 = new Student() { Name = "Jimmy", Gender = "Male", Grade = 95 };
            Student student3 = new Student() { Name = "Jane", Gender = "Female", Grade = 98 };
            Student student4 = new Student() { Name = "Jane", Gender = "Female", Grade = 98 };
            Student student5 = new Student();

            bool test1 = student1.Equals(student2);
            bool test2 = student1.Equals(student3);
            bool test3 = student3.Equals(student4);
            bool test4 = student2.Equals(student5);

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Console.WriteLine(test3);
            Console.WriteLine(test4);
            Console.ReadLine();
        }