Exemple #1
0
        public static void Main(string[] args)
        {
            Student paul  = new Student("Paul");
            Student sally = new Student("Sally");

            paul.AddGrade(3, 4.0);
            paul.AddGrade(4, 3.0);
            sally.AddGrade(3, 3.0);
            sally.AddGrade(3, 3.5);


            int    paulNumberOfCredits = paul.NumberOfCredits;
            string paulGradeLevel      = paul.GradeLevel;
            double paulGpa             = paul.Gpa;


            int    sallyNumberOfCredits = sally.NumberOfCredits;
            string sallyGradeLevel      = sally.GradeLevel;
            double sallyGpa             = sally.Gpa;

            paul.NumberOfCredits  = 91;
            sally.NumberOfCredits = 61;
            paulGradeLevel        = paul.GetGradeLevel();
            sallyGradeLevel       = sally.GetGradeLevel();

            Console.WriteLine("Paul Number of Credits = " + paul.NumberOfCredits.ToString());

            Console.WriteLine("Paul's info: ");
            Console.WriteLine("Gpa = " + Math.Round(paul.Gpa, 2, MidpointRounding.AwayFromZero).ToString());
            Console.WriteLine("Grade Level = " + paulGradeLevel);
            Console.WriteLine("Sally's info: ");
            Console.WriteLine("Gpa = " + Math.Round(sally.Gpa, 2, MidpointRounding.AwayFromZero).ToString());

            Console.WriteLine("Grade Level = " + sallyGradeLevel);

            // use custom ToString() method written below

            Console.WriteLine(paul.ToString());
            Console.WriteLine(sally.ToString());


            //use custom Equals and GetHashCode() methods written below

            Console.WriteLine("paul == sally, using customn Equals() is : " + paul.Equals(sally).ToString());
            Console.WriteLine("GetHasCode() for paul is: " + paul.GetHashCode());
            Console.WriteLine("GetHasCode() for sally is: " + sally.GetHashCode());

            Console.ReadLine();
        }