Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. private static List<Student> _students = new List<Student>();
  2.         static public void AddStudent()
  3.         {
  4.             bool again = true;
  5.             try
  6.             {
  7.                 Console.Clear();
  8.                 Console.WriteLine("UIS - ADDING A NEW STUDENT");
  9.                 Console.WriteLine("---------------------------");
  10.  
  11.                 Console.Write("Enter student name: ");
  12.                 string name = Console.ReadLine();
  13.                 Console.Write("Enter student's last name: ");
  14.                 string surname = Console.ReadLine();
  15.                 Console.Write("Enter the specialty of the student: ");
  16.                 string specialty = Console.ReadLine();
  17.                 Console.Write("Enter the year of birth of the student: ");
  18.  
  19.                 while (again)
  20.                 {
  21.                     string input = Console.ReadLine();
  22.                     if (Int32.TryParse(input, out int year))
  23.                     {
  24.                         Student newStundent = new Student(name, surname, specialty, year);
  25.                         _students.Add(newStundent);
  26.                         Console.WriteLine("\nCreated " + newStundent);
  27.                         again = false;
  28.                     }
  29.                     else
  30.                     {
  31.                         Console.WriteLine("Please enter the number!");
  32.                         Console.ReadKey();
  33.  
  34.                         Console.Clear();
  35.                         Console.WriteLine("UIS - ADDING A NEW STUDENT");
  36.                         Console.WriteLine("---------------------------");
  37.                         Console.WriteLine("Enter student name: " + name);
  38.                         Console.WriteLine("Enter student's last name: " + surname);
  39.                         Console.WriteLine("Enter the specialty of the student: " + specialty);
  40.                         Console.Write("Enter the year of birth of the student: ");
  41.                     }
  42.                 }
  43.             }
  44.             catch (Exception ex)
  45.             {
  46.                 Console.WriteLine(ex.Message);
  47.                 Console.ReadKey();
  48.             }
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement