Esempio n. 1
0
        public static new Employee Read(TextReader input)
        {
            string       str     = input.ReadLine();
            StringReader reader  = new StringReader(str);
            Person       tempper = Person.Read(reader);

            string[] components    = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] jobComponents = components[2].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (jobComponents.Length < 3)
            {
                throw new FormatException("Unaxpected lenght");
            }
            string department = null;
            string jobTitle   = null;
            double salary     = 0;

            try
            {
                department = jobComponents[0];
                jobTitle   = jobComponents[1];
                salary     = double.Parse(jobComponents[2]);
            }
            catch (FormatException ex)
            {
                Console.WriteLine("Unaxpected format exception");
            }
            return(new Employee(tempper, department, jobTitle, salary));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the random person.
        /// </summary>
        /// <returns>The random person.</returns>
        /// <param name="names">Names.</param>
        /// <param name="uid">Uid.</param>
        // TODO: static Person GetRandomPerson(string[][] names, uint uid);

        static void Main(string[] args)
        {
            Student stud = new Student("Иван", "Иванов", "Иванович", Gender.Male, "ПОКС", 1, 2);

            // ToString() вызывается автоматически при преобразовании к строке
            Console.WriteLine(stud);
            // ToString() - виртуальная функция: будет позднее связывание
            Console.WriteLine(stud as Person);

            // FullName - не виртуальное свойство: будет раннее связывание
            Console.WriteLine(stud.FullName);
            Console.WriteLine((stud as Person).FullName);

            // Вызов статического метода
            Person pers = Person.Read(Console.In);

            Student stud2 = new Student(pers, "БТ", 3, 1);

            Console.WriteLine(stud2);
        }
Esempio n. 3
0
        /// <summary>
        /// Read the specified input.
        /// </summary>
        // TODO: public static new Student Read(TextReader input);
        public static new Student Read(TextReader input)
        {
            string       str     = input.ReadLine();
            StringReader reader  = new StringReader(str);
            Person       tempper = Person.Read(reader);

            string[] components      = str.Split(';');
            string[] trackComponents = components[2].Split('-');
            if (trackComponents.Length < 2)
            {
                throw new FormatException("Unaxpected lenght");
            }
            if (trackComponents[1].Length != 2)
            {
                throw new FormatException("Unaxpected group or course");
            }
            string group  = trackComponents[1][1].ToString();
            string course = trackComponents[1][0].ToString();
            string track  = trackComponents[0];

            return(new Student(tempper, track, uint.Parse(course), uint.Parse(group)));
        }