Advertisement
Guest User

OrderByAge

a guest
Feb 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace OrderByAge
  6. {
  7. class StartUp
  8. {
  9. static void Main(string[] args)
  10. {
  11. var people = new List<People>();
  12.  
  13. while (true)
  14. {
  15. var input = Console.ReadLine().Split();
  16. var name = input[0];
  17.  
  18. if (name == "End")
  19. {
  20. break;
  21. }
  22. else
  23. {
  24. var id = input[1];
  25. var age = int.Parse(input[2]);
  26.  
  27. people.Add(new People(name,id,age));
  28. }
  29. }
  30.  
  31. Console.WriteLine(string.Join(" ", people.OrderBy(x=>x.Age)));
  32. }
  33. }
  34.  
  35. class People
  36. {
  37. public string Name { get; set; }
  38. public string Id { get; set; }
  39. public int Age { get; set; }
  40.  
  41. public People(string name, string id, int age)
  42. {
  43. this.Name = name;
  44. this.Id = id;
  45. this.Age = age;
  46. }
  47.  
  48. public override string ToString()
  49. {
  50. return $"{Name} with ID: {Id} is {Age} years old.{Environment.NewLine}";
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement