LINQ ascending Query Keyword using C# in ASP.Net

Updated on 06 Apr 2012,
Published on 15 Sep 2010

The "ascending" contextual keyword in query expressions is used with LINQ orderby clause to specify that the sort order for the returning result sequence must be in increasing order i.e. from smallest to the largest. By default the orderby clause returns the resulting sequence in ascending order because "ascending" is the default keyword for orderby clause and you may omit it in the query expression.  Now let's understand the use ascending keyword with the help example.

Example

int[] numbersArray = { 37, 40, 20, 23, 25, 27, 30, 5, 7, 10, 13, 33, 35, 15, 17 };

var numbers = from n in numbersArray
                orderby n ascending
                select n;

foreach (int number in numbers)
{
    Response.Output.Write("{0} ", number);
}

// Output:         
// 5 7 10 13 15 17 20 23 25 27 30 33 35 37 40

The above C# LINQ example shows the use of "ascending" contextual keyword with orderby clause to arrange the sort order of results from smallest to largest.

Continue to the next tutorial: LINQ descending Query Keyword using C# in ASP.Net to learn how to specify the sort criteria in a query expression.

0 Responses to "LINQ ascending Query Keyword using C# in ASP.Net"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers