private static void Main()
        {
            var firstStudent = new Student();
            firstStudent.Name = "Bai Ivan";
            firstStudent.Age = 68;
            Console.WriteLine(firstStudent); // called firstStudent.ToString()

            var secondStudent = new Student();
            if (firstStudent != secondStudent)
            {
                // it is true
                Console.WriteLine("{0} != {1}", firstStudent, secondStudent);
            }

            secondStudent.Name = "Bai Ivan";
            secondStudent.Age = 68;
            if (firstStudent == secondStudent)
            {
                // it is true
                Console.WriteLine("{0} == {1}", firstStudent, secondStudent);
            }

            secondStudent.Age = 70;
            if (firstStudent != secondStudent)
            {
                // it is true
                Console.WriteLine("{0} != {1}", firstStudent, secondStudent);
            }
        }
Exemplo n.º 2
0
        public int CompareTo(Student other)
        {
            if (other == null)
            {
                throw new ArgumentException("Student is null");
            }

            var ageComparison = this.Age.CompareTo(other.Age);
            if (ageComparison == 0)
            {
                return this.Name.CompareTo(other.Name);
            }

            return ageComparison;
        }