This documentation is archived and is not being maintained.

IOrderedEnumerable<TElement> Interface

Represents a sorted sequence.

Namespace:  System.Linq
Assembly:  System.Core (in System.Core.dll)

public interface IOrderedEnumerable<TElement> : IEnumerable<TElement>, 
	IEnumerable

Type Parameters

TElement

The type of the elements of the sequence.

This type is enumerable because it inherits from IEnumerable<T>.

The extension methods ThenBy and ThenByDescending operate on objects of type IOrderedEnumerable<TElement>. An object of type IOrderedEnumerable<TElement> can be obtained by calling one of the primary sort methods, OrderBy or OrderByDescending, which return an IOrderedEnumerable<TElement>. ThenBy and ThenByDescending, the subordinate sort methods, in turn also return an object of type IOrderedEnumerable<TElement>. This design allows for any number of consecutive calls to ThenBy or ThenByDescending, where each call performs a subordinate ordering on the sorted data returned from the previous call.

The following example demonstrates how to perform a primary and secondary ordering on an array of strings. It also demonstrates that the resulting IOrderedEnumerable<TElement> is enumerable.

// Create an array of strings to sort.
string[] fruits = { "apricot", "orange", "banana", "mango", "apple", "grape", "strawberry" };

// Sort the strings first by their length and then alphabetically 
// by passing the identity selector function.
IOrderedEnumerable<string> sortedFruits1 =
    fruits.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);

// Output the resulting sequence of strings. 
foreach (string fruit in sortedFruits1)
    Console.WriteLine(fruit);

// This code produces the following output: 
// 
// apple 
// grape 
// mango 
// banana 
// orange 
// apricot 
// strawberry

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0
Show: