Advertisement
silvana1303

students

Oct 11th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace classes
  6. {
  7.     class Student
  8.     {
  9.         public string FirstName { get; set; }
  10.         public string LasttName { get; set; }
  11.         public int Age { get; set; }
  12.         public string Hometown { get; set; }
  13.  
  14.     }
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             string[] input = Console.ReadLine().Split().ToArray();
  20.  
  21.             List<Student> list = new List<Student>();
  22.  
  23.             while (input[0] != "end")
  24.             {
  25.              
  26.                 string firstName = input[0];
  27.                 string lastName = input[1];
  28.                 int age = int.Parse(input[2]);
  29.                 string hometown = input[3];
  30.  
  31.                 Student student = new Student();
  32.                 {
  33.                     student.FirstName = firstName;
  34.                     student.LasttName = lastName;
  35.                     student.Age = age;
  36.                     student.Hometown = hometown;
  37.                 }
  38.  
  39.                 list.Add(student);
  40.  
  41.                 input = Console.ReadLine().Split().ToArray();
  42.             }
  43.  
  44.             string last = Console.ReadLine();
  45.  
  46.             List<Student> filtered = list.Where(x => x.Hometown == last).ToList();
  47.  
  48.             foreach (var student in filtered)
  49.             {
  50.                 Console.WriteLine($"{student.FirstName} { student.LasttName} is { student.Age } years old.");
  51.             }
  52.            
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement