Advertisement
Grimmjow1

OrderByAge

Jun 28th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace OrderByAge
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<Human> humans = new List<Human>();
  12.             while (true)
  13.             {
  14.                 string data = Console.ReadLine();
  15.                 if (data=="End")
  16.                 {
  17.                     break;
  18.                 }
  19.                 string[] arg = data.Split();
  20.                 var human = new Human(arg[0], arg[1],int.Parse( arg[2]));
  21.                 humans.Add(human);
  22.             }
  23.             foreach (var item in humans.OrderBy(x=>x.Age))
  24.             {
  25.                 Console.WriteLine(item.ToString());
  26.             }
  27.         }
  28.     }
  29.     class Human
  30.     {
  31.         public Human(string name,string id,int age)
  32.         {
  33.             this.Name = name;
  34.             this.Id = id;
  35.             this.Age = age;
  36.  
  37.         }
  38.         public string Name { get; set; }
  39.         public string Id{ get; set; }
  40.         public int Age { get; set; }
  41.         public override string ToString()
  42.         {
  43.             return $"{this.Name} with ID: {this.Id} is {this.Age} years old.";
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement