Esempio n. 1
0
 public Student(Person personData, Education education, int groupNumber)
     : base(personData?.FirstName, personData?.LastName, personData?.Birthday ?? DateTime.MinValue)
 {
     Education = education;
     GroupNumber = groupNumber;
 }
Esempio n. 2
0
        static void Main()
        {
            var person1 = new Person("Dzmitry", "Paulouski", new DateTime(1994, 3, 1));
            var person2 = person1.DeepCopy() as Person;

            Console.WriteLine($"Person 1:\n{person1}\nHashcode: {person1.GetHashCode()}");
            Console.WriteLine();
            Console.WriteLine($"Person 2:\n{person2}\nHashcode: {person2?.GetHashCode()}");
            Console.WriteLine();
            Console.WriteLine($"Is references equals: {ReferenceEquals(person1, person2)}");
            Console.WriteLine($"Is equals: {person1.Equals(person2)}");


            var student = new Student(
                person1,
                Education.Specialist,
                500);

            student.AddExams(
                new Exam { Date = DateTime.Now, DisciplineName = "Math", Mark = 3 },
                new Exam { Date = DateTime.Parse("01.12.2015"), DisciplineName = "English", Mark = 9 });

            student.AddTests(
                new Test {DisciplineName = "Math", IsPassed = true},
                new Test {DisciplineName = "English", IsPassed = true});

            Console.WriteLine();
            Console.WriteLine(student);
            Console.WriteLine();

            var studentCopy = student.DeepCopy();
            student.FirstName = "Dmitry";
            
            Console.WriteLine();
            Console.WriteLine((Student)studentCopy);


            try
            {
                student.GroupNumber = 9999;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            
            Console.WriteLine();

            foreach (var item in student.GetExamsAndTestsEnumerator())
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("Exams with mark more than 3:");
            foreach (var item in student.GetExamWithMarkMoreThan(3))
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 3
0
 private bool PersonEquals(Person person) 
     => Birthday == person.Birthday &&
        FirstName.Equals(person.FirstName, StringComparison.InvariantCultureIgnoreCase) &&
        LastName.Equals(person.LastName, StringComparison.InvariantCultureIgnoreCase);