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