Advertisement
Katina_

Students

Jun 25th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. //Class
  6. namespace Students
  7. {
  8.     class Student
  9.     {
  10.         public string FirstName { get; set; }
  11.         public string LastName { get; set; }
  12.         public int Age { get; set; }
  13.         public string HomeTown { get; set; }
  14.     }
  15. }
  16.  
  17. //Main
  18. namespace Students
  19. {
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             List<Student> students = new List<Student>();
  25.  
  26.             while (true)
  27.             {
  28.                 string command = Console.ReadLine();
  29.                 string[] data = command.Split();
  30.  
  31.                 if (command == "end")
  32.                 {
  33.                     break;
  34.                 }
  35.  
  36.                 string firstName = data[0];
  37.                 string lastName = data[1];
  38.                 int age = int.Parse(data[2]);
  39.                 string homeTown = data[3];
  40.  
  41.                 Student student = new Student();
  42.  
  43.                 student.FirstName = firstName;
  44.                 student.LastName = lastName;
  45.                 student.Age = age;
  46.                 student.HomeTown = homeTown;
  47.  
  48.                 students.Add(student);
  49.  
  50.             }
  51.  
  52.             string nameOfCity = Console.ReadLine();
  53.  
  54.             foreach(Student student in students)
  55.             {
  56.                 if(student.HomeTown == nameOfCity)
  57.                 {
  58.                     Console.WriteLine($"{student.FirstName} {student.LastName} is {student.Age} years old.");
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement