コード例 #1
0
        public static void Main()
        {
            Student st1 = new Student("Pesho", "Peshov", "Peshov");
            st1.SSN = 555;
            st1.Specialty = Specialties.spec2;

            Student st2 = st1.Clone() as Student;

            Console.WriteLine("\tOriginal student data\n");
            Console.WriteLine(st1);

            Console.WriteLine("\tCloned student data\n");
            Console.WriteLine(st2);

            Console.WriteLine("st1 == st2 ? - {0}", st1 == st2);
            Console.WriteLine();

            Console.WriteLine("Enter new SSN number for student 2 (different from 555)");
            Console.Write("SSN = ");
            st2.SSN = long.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("st1.CompareTo(st2) - {0}", st1.CompareTo(st2));

            Console.WriteLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //1.
            var Antoan = new Student("Antoan", "Petrov", "Elenkov", 14690, "Sin City", "+12345678",
                "*****@*****.**", 5, Specialitiy.CivilEngineering, University.UACG, Faculty.Mathematic);
            var Antoan2 = new Student("Antoan", "Petrov", "Elenkov", 14690, "Sin City", "+12345678",
                "*****@*****.**", 5, Specialitiy.CivilEngineering, University.UACG, Faculty.Mathematic);
            Console.WriteLine(Antoan.ToString());

            Console.WriteLine("\nChecks if getHashCode() is implemented properly:");
            Console.WriteLine(Antoan.GetHashCode());
            Console.WriteLine(Antoan2.GetHashCode());

            //2.IClonable - Clone Object
            Console.WriteLine("\nThis is the deep copy:");
            var AntoanCopy = Antoan.Clone();
            Console.WriteLine(AntoanCopy);

            //3.Implement the IComparable<Student> interface to compare students by names (as first criteria,
            //in lexicographic order) and by social security number (as second criteria, in increasing order).
            Console.WriteLine("\nCompare student Antoan with his copy:");
            Console.WriteLine(Antoan.CompareTo(Antoan2));
        }