Exemple #1
0
        static void Main(string[] args)
        {
            //ToString
            Program program = new Program();

            Console.WriteLine(program.ToString() + "\n");

            //GetType
            Computer computer = new Computer();
            Type     type     = computer.GetType();

            Console.WriteLine(type.FullName);
            Console.WriteLine(type.IsClass);
            Console.WriteLine(type.IsArray + "\n");

            //typeof
            Type type1 = typeof(double);

            Console.WriteLine(type1.FullName);
            Console.WriteLine(typeof(System.Int16).FullName + "\n");

            //equals
            int n = 5;

            Console.WriteLine(n.Equals(5));

            //클래스는 포인터 주소로 비교를한다(디폴트)
            Notebook notebook0 = new Notebook();
            Notebook notebook1 = new Notebook();

            Console.WriteLine(notebook0.Equals(notebook1) + "\n");

            //스트링은 재정의해서 문자열을 비교한다
            string txt1 = new string(new char[] { 't', 'e', 'x', 't' });
            string txt2 = new string(new char[] { 't', 'e', 'x', 't' });

            Console.WriteLine(txt1.Equals(txt2) + "\n");

            //Gethashcode
            short n1 = 256;
            short n2 = 32750;
            short n3 = 256;

            Console.WriteLine(n1.GetHashCode());
            Console.WriteLine(n2.GetHashCode());
            Console.WriteLine(n3.GetHashCode() + "\n");

            Console.WriteLine(notebook0.GetHashCode());
            Console.WriteLine(notebook1.GetHashCode());
        }
        public void TestEqual()
        {
            Notebook instance1 = new Notebook();
            Notebook instance2 = new Notebook();
            // UE 1
            Unit u = new Unit();

            u.Coef = 2;

            instance1.AddUnit(u);
            instance2.AddUnit(u);

            Module m1 = new Module();
            Module m2 = new Module();

            m1.Coef = 2;
            m2.Coef = 4;

            m1.Name = "Maths";
            m2.Name = "ProgCSharp";

            Exam e1 = new Exam();
            Exam e2 = new Exam();
            Exam e3 = new Exam();

            // Ajout des exams pour le premier module
            e1.Module = m1;
            e1.Coef   = 1;
            e1.Score  = 15;

            instance1.Exams.Add(e1);
            instance2.Exams.Add(e1);

            // Ajout pour le 2eme module
            e2.Module = m2;
            e2.Coef   = 2;
            e2.Score  = 10;

            instance1.Exams.Add(e2);
            instance2.Exams.Add(e2);

            e3.Module = m2;
            e3.Coef   = 2;
            e3.Score  = 20;

            u.AddModule(m1);
            u.AddModule(m2);

            instance1.Exams.Add(e3);
            instance2.Exams.Add(e3);

            // UE 2
            Unit u2 = new Unit();

            u2.Coef = 6;

            instance1.AddUnit(u2);
            instance2.AddUnit(u2);

            Module m3 = new Module();
            Module m4 = new Module();

            m3.Coef = 1;
            m4.Coef = 1;

            m3.Name = "Anglais";
            m4.Name = "ExprCom";

            Exam e4 = new Exam();
            Exam e5 = new Exam();
            Exam e6 = new Exam();

            // Ajout des exams pour le premier module
            e4.Module = m3;
            e4.Coef   = 4;
            e4.Score  = 14;

            instance1.Exams.Add(e4);
            instance2.Exams.Add(e4);

            // Ajout pour le 2eme module
            e5.Module = m4;
            e5.Coef   = 1;
            e5.Score  = 15;

            instance1.Exams.Add(e5);
            instance2.Exams.Add(e5);

            e6.Module = m4;
            e6.Coef   = 1;
            e6.Score  = 15;

            instance1.Exams.Add(e6);
            instance2.Exams.Add(e6);

            u2.AddModule(m3);
            u2.AddModule(m4);

            // Nous savons ici que instance1 et instance2 ont recu les meme ajouts
            Assert.True(instance1.Equals(instance2));
        }