Advertisement
DyNaMiXx7

Untitled

Mar 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07OrderByAge
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<People> people = new List<People>();
  12.  
  13.             string input = string.Empty;
  14.             while ((input = Console.ReadLine()) != "End")
  15.             {
  16.                 string[] personInfo = input.Split(" ");
  17.                 string name = personInfo[0];
  18.                 string id = personInfo[1];
  19.                 int age = int.Parse(personInfo[2]);
  20.  
  21.                 People person = new People(name, id, age);
  22.                 people.Add(person);
  23.             }
  24.  
  25.             people = people.OrderBy(p => p.Age).ToList();
  26.  
  27.             people.ForEach(p => Console.WriteLine($"{p.Name} with ID: {p.Id} is {p.Age} years old."));
  28.         }
  29.     }
  30.  
  31.     class People
  32.     {
  33.         public string Name { get; set; }
  34.         public string Id { get; set; }
  35.         public int Age { get; set; }
  36.  
  37.         public People(string name, string id, int age)
  38.         {
  39.             Name = name;
  40.             Id = id;
  41.             Age = age;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement