Пример #1
0
 private static void ReadLastName(Person tempPerson)
 {
     while (true)
     {
         Console.WriteLine("Please enter person's last name:");
         try
         {
             string currentName = Console.ReadLine();
             tempPerson.LastName = currentName;
             break;
         }
         catch (ArgumentNullException ex)
         {
             Console.Error.WriteLine("Exception: {0}", ex.Message);
         }
     }
 }
Пример #2
0
 public static void Main()
 {
     //Person pesho = new Person("Ivo", "Ivov", 28);
     try
     {
         Person noname = new Person(string.Empty, "pepov", 88);
     }
     catch(ArgumentNullException ex)
     {
         Console.WriteLine("Exception thrown: {0}", ex.Message); 
     }
     catch (ArgumentOutOfRangeException ex)
     {
         Console.WriteLine("Exception thrown: {0}", ex.Message);
     }
     //Person nolast = new Person("Pepo", null, 55);
     //Person negativ = new Person("Gogo", "Gogov", -5);
     //Person old = new Person("Ivo", "Gogov", 121);
 }
Пример #3
0
        static void Main(string[] args)
        {
            List<Person> collection = new List<Person>();

            while (true)
            {
                Person tempPerson = new Person();

                ReadFirstName(tempPerson);

                ReadLastName(tempPerson);

                ReadAge(tempPerson);

                collection.Add(tempPerson);
                Console.WriteLine("Person added!");

                break;
            }
        }
Пример #4
0
 private static void ReadAge(Person tempPerson)
 {
     while (true)
     {
         Console.WriteLine("Please enter person's age:");
         try
         {
             int temp = int.Parse(Console.ReadLine());
             tempPerson.Age = temp;
             break;
         }
         catch (ArgumentNullException ex)
         {
             Console.Error.WriteLine("Exception: {0}", ex.Message);
         }
         catch (ArgumentOutOfRangeException ex)
         {
             Console.Error.WriteLine("Exception: {0}.", ex.Message);
         }
     }
 }