RNovachkov

Untitled

Jun 24th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01.OrderByAge
  8. {
  9.     class Program
  10.     {
  11.         public class Persons
  12.         {
  13.             public string Name { get; set; }
  14.  
  15.             public string ID { get; set; }
  16.  
  17.             public int Age { get; set; }
  18.         }
  19.         static void Main(string[] args)
  20.         {
  21.             var dataInput = Console.ReadLine();
  22.  
  23.             var newPersons = new List<Persons>();
  24.  
  25.             while (dataInput != "End")
  26.             {
  27.                 if (dataInput != "End")
  28.                 {
  29.                     var infoSplit = dataInput.Split().ToArray();
  30.                     var name = infoSplit[0];
  31.                     var idNumber = infoSplit[1];
  32.                     var age = int.Parse(infoSplit[2]);
  33.                     Persons eachPerson = new Persons();
  34.                     eachPerson.Name = name;
  35.                     eachPerson.ID = idNumber;
  36.                     eachPerson.Age = age;
  37.  
  38.                     newPersons.Add(eachPerson);
  39.                 }
  40.  
  41.                 dataInput = Console.ReadLine();
  42.             }
  43.  
  44.             foreach (var person in newPersons.OrderBy(x => x.Age))
  45.             {
  46.                 Console.WriteLine($"{person.Name} with ID: {person.ID} is {person.Age} years old.");
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment