Exemple #1
0
        public static void Main()
        {
            Person   p = new Person("John", "Smith", "Bristol");
            Student  s = new Student("Brian", "Cartman", "London", "99678", "CS");
            Lecturer l = new Lecturer("Fred", "Bloggs", "Birmingham", "N12");

            Console.WriteLine("\nInstantiating a person p, student s and lecturer l");
            Console.WriteLine($"Person p: {p} ");
            Console.WriteLine($"Student s: {s} ");
            Console.WriteLine($"Lecturer l: {l} ");
            Console.WriteLine("\nBasic tests, showing values after instantiating basic objects:");
            Console.WriteLine($"Student no: {s.GetStudentNo()} ");
            Console.WriteLine($"Student address: {s.GetAddress()} ");
            Console.WriteLine($"Person address: {p.GetAddress()} ");
            Console.WriteLine($"Lecturer address: {l.GetAddress()} ");
            Console.WriteLine($"Lecturer office: {l.GetOfficeNo()} ");
            // ---

            Console.Write(
                "\nNow, copying the object and updating first name, demonstrating reference semantics in objects, i.e.,");
            Console.WriteLine("the update of first name in q affects p, too");
            var q = p;

            Console.WriteLine($"Person p: {p} ");
            Console.WriteLine($"Person q: {q} ");
            q.FName = "Will";
            Console.WriteLine($"Person p: {p} ");
            Console.WriteLine($"Person q: {q} ");

            Console.WriteLine(
                "\nHere we use the overriden ToString() method, implemented as a generic serialisation method:");
            Console.WriteLine($"Student: {s} ");
            Console.WriteLine($"Student: {s} ");
            Console.WriteLine($"Lecturer: {l} ");
        }