LINQ Keywords: orderby
The orderby keyword is used to sort records in a a where condition. Here is an example:
1 min read33 words1 code sample
Where is the Condition#
The orderby keyword is used to sort records in a a where condition. The following example shows this:
C#
using System;
using System.Linq;
using System.Collections.Generic;
public class Exercise
{
public static int Main()
{
var numbers = new List<int>();
numbers.Add(12);
numbers.Add(45);
numbers.Add(38);
numbers.Add(5);
numbers.Add(128);
numbers.Add(525);
numbers.Add(2448);
numbers.Add(39);
numbers.Add(632);
numbers.Add(207);
var number = from n
in numbers
where n % 2 != 0
orderby n ascending
select n;
foreach (var member in number)
Console.WriteLine(member.ToString());
Console.WriteLine();
return 0;
}
}The output would be:
Home Copyright © 2008-2010 FunctionX, Inc. Next

