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