Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- //Class
- namespace Students
- {
- class Student
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public int Age { get; set; }
- public string HomeTown { get; set; }
- }
- }
- //Main
- namespace Students
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> students = new List<Student>();
- while (true)
- {
- string command = Console.ReadLine();
- string[] data = command.Split();
- if (command == "end")
- {
- break;
- }
- string firstName = data[0];
- string lastName = data[1];
- int age = int.Parse(data[2]);
- string homeTown = data[3];
- Student student = new Student();
- student.FirstName = firstName;
- student.LastName = lastName;
- student.Age = age;
- student.HomeTown = homeTown;
- students.Add(student);
- }
- string nameOfCity = Console.ReadLine();
- foreach(Student student in students)
- {
- if(student.HomeTown == nameOfCity)
- {
- Console.WriteLine($"{student.FirstName} {student.LastName} is {student.Age} years old.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement