Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IOrderedEnumerable(Of TElement) Interface

Represents a sorted sequence.

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

'Declaration
Public Interface IOrderedEnumerable(Of TElement) _
	Inherits IEnumerable(Of TElement), IEnumerable
'Usage
Dim instance As IOrderedEnumerable(Of TElement)

Type Parameters

TElement

The type of the elements of the sequence.

This type is enumerable because it inherits from IEnumerable(Of T).

The extension methods ThenBy and ThenByDescending operate on objects of type IOrderedEnumerable(Of TElement). An object of type IOrderedEnumerable(Of TElement) can be obtained by calling one of the primary sort methods, OrderBy or OrderByDescending, which return an IOrderedEnumerable(Of TElement). ThenBy and ThenByDescending, the subordinate sort methods, in turn also return an object of type IOrderedEnumerable(Of 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(Of TElement) is enumerable.

' Create an array of strings to sort. 
Dim fruits() As String = _
    {"apricot", "orange", "banana", "mango", "apple", "grape", "strawberry"}

' Sort the strings first by their length and then alphabetically by passing the identity selector function. 
Dim sortedFruits1 As IOrderedEnumerable(Of String) = _
    fruits.OrderBy(Function(ByVal fruit) fruit.Length).ThenBy(Function(ByVal fruit) fruit)

Dim output As New System.Text.StringBuilder
' Output the resulting sequence of strings. 
For Each fruit As String In sortedFruits1
    output.AppendLine(fruit)
Next 

' Display the results.
MsgBox(output.ToString())

' 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

Community Additions

Show:
© 2017 Microsoft