Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Sort Multiple Column using Orderby and ThenBy LINQ
WhatsApp
Mano Kali
Jun 02
2016
1.2
k
0
0
List<Student> students =
new
List<Student()
{
new
Student(2,
"John"
, 485),
new
Student(2,
"Anitha"
, 485),
new
Student(3,
"Mano"
, 481),
new
Student(1,
"Rakesh"
, 495)
};
Console.WriteLine(
"\nBefore Sort \n"
);
students.ForEach(x =>
{
Console.WriteLine($
"Rank : {x.Rank} & Name :{x.Name} & Total :{x.Total} "
);
});
students = students.OrderBy(x => x.Rank).ThenBy(y => y.Name).ToList();
Console.WriteLine(
"\nAfter Sort\n"
);
students.ForEach(x => {
Console.WriteLine($
"Rank : {x.Rank} & Name :{x.Name} & Total :{x.Total} "
);
});
LINQ
OrderBy and ThenBy
Up Next
Sort Multiple Column using Orderby and ThenBy LINQ