SHARE
TWEET

Order by Age

a guest Feb 28th, 2020 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _7._Order_by_Age
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string command = Console.ReadLine();
  12.             List<Person> people = new List<Person>();
  13.             while (command != "End")
  14.             {
  15.                 string[] data = command.Split(" ");
  16.  
  17.                 string name = data[0];
  18.                 string id = data[1];
  19.                 int age = int.Parse(data[2]);
  20.  
  21.                 Person person = new Person(name, id, age);
  22.                 people.Add(person);
  23.  
  24.                 command = Console.ReadLine();
  25.             }
  26.             people = people.OrderBy(x => x.Age).ToList();
  27.  
  28.             foreach (var person in people)
  29.             {
  30.                 Console.WriteLine($"{person.Name} with ID: {person.Id} is {person.Age} years old.");
  31.             }
  32.         }
  33.         class Person
  34.         {
  35.             public string Name { get; set; }
  36.             public string Id { get; set; }
  37.             public int Age { get; set; }
  38.  
  39.             public Person(string name, string id, int age)
  40.             {
  41.                 this.Name = name;
  42.                 this.Id = id;
  43.                 this.Age = age;
  44.             }
  45.         }
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top