Sunday, May 25, 2008

Visual Studio 2008 - LINQ Ordering Operators Sample

OrderBy - Simple
This sample prints an alphabetically sorted version of an input string array. The sample uses orderby to perform the sort.
publicvoid Linqsample()
{
string[] colors = { "Blue", "red", "green" };
var sortedcolorss = from c in colors
orderby c
select c;
Console.WriteLine("The sorted list of colors:");
foreach (var c in sortedcolors)
{
Console.WriteLine(c);
}
}
Result
The sorted list of words:
Blue
green
red

No comments: