Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var a = new Abiturient("Екатерина", "Петрович", "Дмитриевна", "Громова", "1234567", new[] { 9, 8, 10, 9, 8 });
            var b = new Abiturient("Валерий", "Коклюшкин", "Аристархович");
            var c = new Abiturient("Виктор", "Петучевский", "Геннадьевич", "ул. Пушкина, дом Колотушкина");

            var x1 = new Abiturient("Мария", "Петрова", "Витальевна");
            var x2 = new Abiturient("Мария", "Петрова", "Витальевна");

            b.Marks = new[] { 7, 6, 4, 9, 6 };
            c.Phone = "88005553535";

            a.PrintFullname(out var fullname_a);
            b.PrintFullname(out var fullname_b);
            Console.WriteLine($"Максимальная оценка {fullname_a}: {a.GetMaxMark()}");
            Console.WriteLine($"Средний балл {fullname_b}: {b.GetAverageMark()}");

            Console.WriteLine($"x1 и x2 равны: {x1.Equals(x2)}");

            x1.Phone = "9999";

            Console.WriteLine($"а теперь x1 и x2 равны: {x1.Equals(x2)}");

            Console.WriteLine($"Тип x1 {x1.GetType()}");

            x1.Marks = new[] { 5, 4, 9, 5, 6 };


            Abiturient[] abs = { a, b, c, x1, x2 };

            Console.WriteLine("Неудовлетворительные оценки у:");
            foreach (var abiturient in abs)
            {
                if (abiturient.Marks.Any(m => m < 4))
                {
                    Console.WriteLine($"{abiturient.Name} {abiturient.Surname}");
                }
            }

            Console.WriteLine("Абитуриенты с суммой баллов выше 40:");
            foreach (var abiturient in abs)
            {
                if (abiturient.Marks.Sum() > 40)
                {
                    Console.WriteLine($"{abiturient.Name} {abiturient.Surname}");
                }
            }

            Console.WriteLine(Abiturient.GetMetaInfo());

            var aType = new { Name = "Анастасия", Surname = "Шевцова", Middlename = "Дмитриевна", Address = "Волгоградская 65-8", Phone = "01010101", Marks = new int[] { 9, 8, 10, 7, 9 } };

            Console.WriteLine($"Экземпляр анонимного типа: {aType.Name} {aType.Surname}; адрес: {aType.Address}, телефон: {aType.Phone}");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // First class.
            Abiturient abiturient = new Abiturient(1, "Kaportsev", new int[] { 1, 234, 5, 24, 1 });

            Console.WriteLine(Reflector.GetAssemblyName(abiturient.GetType()));

            if (Reflector.IsPublicConstructors(abiturient.GetType()))
            {
                Console.WriteLine("У класса есть публичные конструкторы...");
            }
            else
            {
                Console.WriteLine("У класса нет публичных конструкторов...");
            }

            Console.WriteLine("Public Methods:");
            foreach (var i in Reflector.GetPublicMethods(abiturient.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Fields:");
            foreach (var i in Reflector.GetFields(abiturient.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Interfaces:");
            foreach (var i in Reflector.GetInterfaces(abiturient.GetType()))
            {
                Console.WriteLine(i);
            }

            Reflector.OutputMetodsNameFromParamType(abiturient.GetType());

            // Second class.
            Student student = new Student("Kaportsev", "POIT");

            Console.WriteLine(Reflector.GetAssemblyName(student.GetType()));

            if (Reflector.IsPublicConstructors(student.GetType()))
            {
                Console.WriteLine("У класса есть публичные конструкторы...");
            }
            else
            {
                Console.WriteLine("У класса нет публичных конструкторов...");
            }

            Console.WriteLine("Public Methods:");
            foreach (var i in Reflector.GetPublicMethods(student.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Fields:");
            foreach (var i in Reflector.GetFields(student.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Interfaces:");
            foreach (var i in Reflector.GetInterfaces(student.GetType()))
            {
                Console.WriteLine(i);
            }

            Reflector.OutputMetodsNameFromParamType(student.GetType());

            // Standart class.
            List <int> standart = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            Console.WriteLine(Reflector.GetAssemblyName(standart.GetType()));

            if (Reflector.IsPublicConstructors(standart.GetType()))
            {
                Console.WriteLine("У класса есть публичные конструкторы...");
            }
            else
            {
                Console.WriteLine("У класса нет публичных конструкторов...");
            }

            Console.WriteLine("Public Methods:");
            foreach (var i in Reflector.GetPublicMethods(standart.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Fields:");
            foreach (var i in Reflector.GetFields(standart.GetType()))
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Interfaces:");
            foreach (var i in Reflector.GetInterfaces(standart.GetType()))
            {
                Console.WriteLine(i);
            }

            Reflector.OutputMetodsNameFromParamType(standart.GetType());

            // Invoke.
            object[] param = new object[1];
            using (StreamReader fstream = new StreamReader(@"C:\Workplace\1University\second_cource\OOTP\Csharp_3sem\Lab12\files\Params.txt"))
            {
                string textFromFile = null;
                while ((textFromFile = fstream.ReadLine()) != null)
                {
                    param[0] = Convert.ToInt32(textFromFile);
                }
            }
            Reflector.Invoke(standart, "Add", param);

            Random rand = new Random();

            param[0] = rand.Next();
            Reflector.Invoke(standart, "Add", param);

            var someClass = Reflector.Create(typeof(Abiturient));

            Console.WriteLine(someClass.ToString());
        }