Program.cs 444 B

1234567891011121314151617181920
  1. List<User> users = new List<User>()
  2. {
  3. new User { Name = "Tom", Age = 33 },
  4. new User { Name = "Bob", Age = 30 },
  5. new User { Name = "Tom", Age = 21 },
  6. new User { Name = "Sam", Age = 43 }
  7. };
  8. var result = users
  9. .OrderBy(u => u.Name)
  10. .ThenBy(u => u.Age);
  11. foreach (User u in result)
  12. Console.WriteLine($"{u.Name} - {u.Age}");
  13. public class User
  14. {
  15. public string Name { get; set; }
  16. public int Age { get; set; }
  17. }