TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Sort Multiple Column using Orderby and ThenBy LINQ
Mano Kali
Jun 02
2016
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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