Advertisement
silvana1303

students 2

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