Пример #1
0
 static void Main()
 {
     var st1 = new Student() { FirstName = "Mimi", LastName = "Ivanova", SSN = 589762, Specialty = Specialty.Mathematics };
     var st2 = new Student() { FirstName = "Mimito", LastName = "Ivanova" };
     var st3 = new Student() { FirstName = "Mimi", LastName = "Ivanova", SSN = 125639, Specialty = Specialty.Informatics };
     Console.WriteLine(st1.Equals(st2));
     Console.WriteLine(st1.Equals(st3));
     Console.WriteLine(st1 == st2);
     Console.WriteLine(st1.ToString());
     Console.WriteLine(st3.GetHashCode());
     Console.WriteLine(st1.Clone().ToString());
     Console.WriteLine(st1.CompareTo(st3));
 }
        public static void Main()
        {
            // Examples
            Student studentIvan = new Student("Ivan", "Manolov", "Kodev", 1175443445, "ul.Asenevci N3, Shumen", "+359895888333", "*****@*****.**", 3, University.Oxford, Specialty.French, Faculty.Alpha);
            Student studentDimcho = new Student("Dimcho", "Buhov", "Kostov", 1145345682, "ul.Padashti kotki, Sopot", "+359895123123", "*****@*****.**", 1, University.Harvard, Specialty.Biology, Faculty.Faculty3);

            // Crate array of Students
            Student[] students = new Student[] { studentIvan,studentDimcho};

            // Print
            Console.WriteLine("All students:\n");
            foreach (var student in students)
            {
                Console.WriteLine(student);
                Console.WriteLine();
            }

            // Check the overrited methods
            Console.WriteLine("\nIs Ivan == Dimcho?\n");
            Console.WriteLine(studentIvan == studentDimcho);

            Console.WriteLine("\nIs Ivan != Dimcho?\n");
            Console.WriteLine(studentIvan != studentDimcho);

            Console.WriteLine("\nIs Ivan equal to Dimcho?\n");
            Console.WriteLine(studentIvan.Equals(studentDimcho));

            Console.WriteLine("\nIvan compared with Dimcho:\n");
            Console.WriteLine(studentIvan.CompareTo(studentDimcho));

            Console.WriteLine("\nIvan HashCode:\n");
            Console.WriteLine(studentIvan.GetHashCode());
            Console.WriteLine("\nDimcho HashCode:\n");
            Console.WriteLine(studentDimcho.GetHashCode());

            Console.WriteLine("\nDimcho is copied...\n");
            var studentDimcho2 = studentDimcho.Clone();                         // Deep clone/sopy , element by element

            Console.WriteLine("\nIs DImcho compared with copied Dimcho?\n");
            Console.WriteLine(studentDimcho.CompareTo(studentDimcho2));

            Console.WriteLine("\nIs Dimcho equals to copied Dimcho?\n");
            Console.WriteLine(studentDimcho.Equals(studentDimcho2));           // Should be true

            Console.WriteLine("\nIs Dimcho equals to copied Dimcho by reference?\n");
            Console.WriteLine(ReferenceEquals(studentDimcho2,studentDimcho)); // Should be false
            Console.WriteLine("\nNice!");



            



        }
Пример #3
0
        static void Main(string[] args)
        {
            Student firstStudent = new Student("Boncho", "Bonchov", "Bonchoto", 13202733, "Ulica nqkva si 33", "+359 8824324234",
                "*****@*****.**", 4, Specialties.Programming,
                University.SofiaUniversity, Faculty.Informatics);

            Student secondStudent = new Student("Spartak", "Spartakiev", "Spartakov", 12224956, "Ulica nqkva si 34", "+359 8854545454",
                "*****@*****.**", 4, Specialties.Art,
                University.NBU, Faculty.Arts);

            Student thirdStudent = new Student("Boncho", "Bonchov", "Bonchoto", 13202733, "Ulica nqkva si 33", "+359 8824324234",
                "*****@*****.**", 4, Specialties.Programming,
                University.SofiaUniversity, Faculty.Informatics);

            Console.WriteLine(firstStudent + "\n");
            Console.WriteLine(secondStudent + "\n");
            Console.WriteLine("Students are equals: " + firstStudent.Equals(secondStudent) + "\n");
            Console.WriteLine("Students are equals: " + firstStudent.Equals(thirdStudent) + "\n");
            Console.WriteLine("Hash code student one: {0}\nHash code student two: {1}\n.",
                firstStudent.GetHashCode(), secondStudent.GetHashCode());
            Console.WriteLine("Equals operator \"==\": {0}\n", firstStudent == thirdStudent);
            Console.WriteLine("Equals operator \"!=\": {0}\n", firstStudent != thirdStudent);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Student firstStudent = new Student("Boncho", "Bonchov", "Bonchoto", 13202733, "Ulica nqkva si 33", "+359 8824324234",
                                               "*****@*****.**", 4, Specialties.Programming,
                                               University.SofiaUniversity, Faculty.Informatics);

            Student secondStudent = new Student("Spartak", "Spartakiev", "Spartakov", 12224956, "Ulica nqkva si 34", "+359 8854545454",
                                                "*****@*****.**", 4, Specialties.Art,
                                                University.NBU, Faculty.Arts);

            Student thirdStudent = new Student("Boncho", "Bonchov", "Bonchoto", 13202733, "Ulica nqkva si 33", "+359 8824324234",
                                               "*****@*****.**", 4, Specialties.Programming,
                                               University.SofiaUniversity, Faculty.Informatics);

            Console.WriteLine(firstStudent + "\n");
            Console.WriteLine(secondStudent + "\n");
            Console.WriteLine("Students are equals: " + firstStudent.Equals(secondStudent) + "\n");
            Console.WriteLine("Students are equals: " + firstStudent.Equals(thirdStudent) + "\n");
            Console.WriteLine("Hash code student one: {0}\nHash code student two: {1}\n.",
                              firstStudent.GetHashCode(), secondStudent.GetHashCode());
            Console.WriteLine("Equals operator \"==\": {0}\n", firstStudent == thirdStudent);
            Console.WriteLine("Equals operator \"!=\": {0}\n", firstStudent != thirdStudent);
        }
Пример #5
0
        public static void Main()
        {
            // Examples
            Student studentIvan   = new Student("Ivan", "Manolov", "Kodev", 1175443445, "ul.Asenevci N3, Shumen", "+359895888333", "*****@*****.**", 3, University.Oxford, Specialty.French, Faculty.Alpha);
            Student studentDimcho = new Student("Dimcho", "Buhov", "Kostov", 1145345682, "ul.Padashti kotki, Sopot", "+359895123123", "*****@*****.**", 1, University.Harvard, Specialty.Biology, Faculty.Faculty3);

            // Crate array of Students
            Student[] students = new Student[] { studentIvan, studentDimcho };

            // Print
            Console.WriteLine("All students:\n");
            foreach (var student in students)
            {
                Console.WriteLine(student);
                Console.WriteLine();
            }

            // Check the overrited methods
            Console.WriteLine("\nIs Ivan == Dimcho?\n");
            Console.WriteLine(studentIvan == studentDimcho);

            Console.WriteLine("\nIs Ivan != Dimcho?\n");
            Console.WriteLine(studentIvan != studentDimcho);

            Console.WriteLine("\nIs Ivan equal to Dimcho?\n");
            Console.WriteLine(studentIvan.Equals(studentDimcho));

            Console.WriteLine("\nIvan compared with Dimcho:\n");
            Console.WriteLine(studentIvan.CompareTo(studentDimcho));

            Console.WriteLine("\nIvan HashCode:\n");
            Console.WriteLine(studentIvan.GetHashCode());
            Console.WriteLine("\nDimcho HashCode:\n");
            Console.WriteLine(studentDimcho.GetHashCode());

            Console.WriteLine("\nDimcho is copied...\n");
            var studentDimcho2 = studentDimcho.Clone();                         // Deep clone/sopy , element by element

            Console.WriteLine("\nIs DImcho compared with copied Dimcho?\n");
            Console.WriteLine(studentDimcho.CompareTo(studentDimcho2));

            Console.WriteLine("\nIs Dimcho equals to copied Dimcho?\n");
            Console.WriteLine(studentDimcho.Equals(studentDimcho2));           // Should be true

            Console.WriteLine("\nIs Dimcho equals to copied Dimcho by reference?\n");
            Console.WriteLine(ReferenceEquals(studentDimcho2, studentDimcho)); // Should be false
            Console.WriteLine("\nNice!");
        }
Пример #6
0
        public static void Main()
        {
            Student firstStudent = new Student();
            Student secondStudent = new Student();
            secondStudent.Course = 5;
            secondStudent.FistName = "Pesho";
            secondStudent.SSN = 6;
            Console.WriteLine(firstStudent == secondStudent);
            Console.WriteLine(firstStudent.Equals(secondStudent));

            Student someStudent = (Student)secondStudent.Clone();
            someStudent.FistName = "Gosho";
            someStudent.SSN = 7;
            Console.WriteLine(secondStudent.FistName);
            Console.WriteLine(someStudent.FistName);
            Console.WriteLine(secondStudent.CompareTo(someStudent));
        }
Пример #7
0
        static void Main(string[] args)
        {
            Student peshoStud = new Student("Pesho", "Petrov", "Peshev", 9006036584, 1, "*****@*****.**", University.SofiaUniversity,
                                            Faculty.Physics, Specialty.Physics);
            Student ivanStud = new Student("Pesho", "Petrov", "Peshev", 9006036584, 1, "*****@*****.**", University.SofiaUniversity,
                                           Faculty.Physics, Specialty.Physics);

            Console.WriteLine(peshoStud.CompareTo(ivanStud));

            Console.WriteLine(peshoStud.Equals(ivanStud));
            Console.WriteLine(peshoStud.GetHashCode());
            Console.WriteLine(ivanStud.GetHashCode());
            Console.WriteLine(peshoStud.ToString());
            Console.WriteLine(peshoStud == ivanStud);
            Console.WriteLine(peshoStud != ivanStud);

            var cloned = ivanStud.Clone() as Student;

            Console.WriteLine(ivanStud.SSN);
            Console.WriteLine(cloned.SSN);
        }
Пример #8
0
 public static bool operator !=(Student student1,
                                Student student2)
 {
     return(!(Student.Equals(student1, student2)));
 }