OrderBy - Simple 2

Query
public void Linq29()
{
string[] words = { "cherry", "apple", "blueberry" };

var sortedWords =
from w in words
orderby w.Length
select w;

Console.WriteLine("The sorted list of words (by length):");
foreach (var w in sortedWords)
{
Console.WriteLine(w);
}
}
Lambda Expression
public void Linq29()
{
string[] words = { "cherry", "apple", "blueberry" };

var sortedWords = words.OrderBy(word => word.Length);

Console.WriteLine("The sorted list of words (by length):");
foreach (var w in sortedWords)
{
Console.WriteLine(w);
}
}
Output
The sorted list of words (by length):
apple
cherry
blueberry
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +