Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace OrderByAge
- {
- class Person
- {
- public Person(string name, string id, int age)
- {
- this.Name = name;
- this.ID = id;
- this.Age = age;
- }
- public string Name { get; set; }
- public string ID { get; set; }
- public int Age { get; set; }
- }
- class Program
- {
- public static void Main()
- {
- List<Person> people = new List<Person>();
- string command;
- while ((command = Console.ReadLine()) != "End")
- {
- string[] personInfo = command.Split(" ");
- string name = personInfo[0];
- string id = personInfo[1];
- int age = int.Parse(personInfo[2]);
- int idIndex = people.FindIndex(x => x.ID == id);
- if (idIndex == -1)
- {
- people.Add(new Person(name, id, age));
- }
- else
- {
- people[idIndex].Name = name;
- people[idIndex].Age = age;
- }
- }
- foreach (var p in people.OrderBy(x => x.Age))
- {
- Console.WriteLine($"{p.Name} with ID: {p.ID} is {p.Age} years old.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement