Advertisement
gospod1978

Object and Class/Student

Oct 24th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Numerics;
  6.  
  7.  
  8. namespace fundamental14
  9. {
  10.     class Student
  11.     {
  12.         public string FirstName { get; set; }
  13.         public string LastName { get; set; }
  14.         public int Age { get; set; }
  15.         public string City { get; set; }
  16.     }
  17.  
  18.     class MainClass
  19.     {
  20.         public static void Main()
  21.         {
  22.             string input;
  23.             List<Student> students = new List<Student>();
  24.  
  25.             while ((input = Console.ReadLine()) != "end")
  26.             {
  27.                 string[] array = input.Split();
  28.                
  29.  
  30.                 string firstName = array[0];
  31.                 string listName = array[1];
  32.                 int age = int.Parse(array[2]);
  33.                 string city = array[3];
  34.                 Student student = new Student();
  35.                 student.FirstName = firstName;
  36.                 student.LastName = listName;
  37.                 student.Age = age;
  38.                 student.City = city;
  39.                 students.Add(student);
  40.             }
  41.             string outputCity = Console.ReadLine();
  42.             List<Student> newListStudent = students.Where(x => x.City == outputCity).ToList();
  43.  
  44.             foreach (Student studentOut in newListStudent)
  45.             {
  46.                 Console.WriteLine($"{studentOut.FirstName} {studentOut.LastName} is {studentOut.Age} years old.");
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement