4
Answers

Orderby clause

Maha

Maha

11y
902
1
This program is given in the following website. Even though the word "ascending" is not in result0 assignment, o/p is in the ascending order. Please explain the reason. Problem is highlighted.
http://www.dotnetperls.com/orderby

using System;
using System.Linq;

class Program
{
static void Main()
{
// Input array.
int[] array = { 2, 5, 3 };

// Use orderby, orderby ascending, and orderby descending.

var result0 = from element in array
orderby element
select element;

var result1 = from element in array
orderby element ascending
select element;

var result2 = from element in array
orderby element descending
select element;

// Print results.
Console.WriteLine("result0");

foreach (var element in result0)
Console.WriteLine(element);

Console.WriteLine("result1");

foreach (var element in result1)
Console.WriteLine(element);

Console.WriteLine("result2");

foreach (var element in result2)
Console.WriteLine(element);

Console.ReadKey();
}
}
/*
result0
2
3
5
result1
2
3
5
result2
5
3
2
*/

Answers (4)