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 string array by string length
Bhuvan Pandey
Jul 07
2016
Code
5.5
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Ascending order:
string
[] city =
new
string
[] {
"Pune"
,
"Mumbai"
,
"Varanasi"
,
"Delhi"
,
"Chennai"
};
var x = from a
in
city
orderby a.Length ascending
select a;
foreach
(var item
in
x)
{
Console.WriteLine(item);
}
Output:
Pune
Delhi
Mumbai
Chennai
Varanasi
Descending order:
string
[] city =
new
string
[] {
"Pune"
,
"Mumbai"
,
"Varanasi"
,
"Delhi"
,
"Chennai"
};
var x = from a
in
city
orderby a.Length descending
select a;
foreach
(var item
in
x)
{
Console.WriteLine(item);
}
Output:
Varanasi
Chennai
Mumbai
Delhi
Pune
Sort string array by string length Advance LINQ Part - 4