1234567891011121314151617181920 |
- List<User> users = new List<User>()
- {
- new User { Name = "Tom", Age = 33 },
- new User { Name = "Bob", Age = 30 },
- new User { Name = "Tom", Age = 21 },
- new User { Name = "Sam", Age = 43 }
- };
- var result = users
- .OrderBy(u => u.Name)
- .ThenBy(u => u.Age);
- foreach (User u in result)
- Console.WriteLine($"{u.Name} - {u.Age}");
- public class User
- {
- public string Name { get; set; }
- public int Age { get; set; }
- }
|