IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement,TKey>, IComparer<TKey>, Boolean) Método

Definición

Realiza una ordenación subsiguiente de los elementos de un objeto IOrderedEnumerable<TElement> según una clave.Performs a subsequent ordering on the elements of an IOrderedEnumerable<TElement> according to a key.

public:
generic <typename TKey>
 System::Linq::IOrderedEnumerable<TElement> ^ CreateOrderedEnumerable(Func<TElement, TKey> ^ keySelector, System::Collections::Generic::IComparer<TKey> ^ comparer, bool descending);
public System.Linq.IOrderedEnumerable<TElement> CreateOrderedEnumerable<TKey> (Func<TElement,TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer, bool descending);
public System.Linq.IOrderedEnumerable<out TElement> CreateOrderedEnumerable<TKey> (Func<out TElement,TKey> keySelector, System.Collections.Generic.IComparer<TKey>? comparer, bool descending);
public System.Linq.IOrderedEnumerable<out TElement> CreateOrderedEnumerable<TKey> (Func<out TElement,TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer, bool descending);
abstract member CreateOrderedEnumerable : Func<'Element, 'Key> * System.Collections.Generic.IComparer<'Key> * bool -> System.Linq.IOrderedEnumerable<'Element>
Public Function CreateOrderedEnumerable(Of TKey) (keySelector As Func(Of TElement, TKey), comparer As IComparer(Of TKey), descending As Boolean) As IOrderedEnumerable(Of TElement)
Public Function CreateOrderedEnumerable(Of TKey) (keySelector As Func(Of Out TElement, TKey), comparer As IComparer(Of TKey), descending As Boolean) As IOrderedEnumerable(Of Out TElement)

Parámetros de tipo

TKey

Tipo de la clave generada por keySelector.The type of the key produced by keySelector.

Parámetros

keySelector
Func<TElement,TKey>

Se utiliza Func<T,TResult> para extraer la clave de cada elemento.The Func<T,TResult> used to extract the key for each element.

comparer
IComparer<TKey>

Comparador IComparer<T> utilizado para comparar las claves de cara a su colocación en la secuencia devuelta.The IComparer<T> used to compare keys for placement in the returned sequence.

descending
Boolean

Es true para ordenar los elementos en orden descendente; es false para ordenar los elementos en orden ascendente.true to sort the elements in descending order; false to sort the elements in ascending order.

Devoluciones

IOrderedEnumerable<TElement>

Una interfaz IOrderedEnumerable<TElement> cuyos elementos se ordenan con arreglo a una clave.An IOrderedEnumerable<TElement> whose elements are sorted according to a key.

Ejemplos

En el ejemplo de código siguiente se muestra cómo utilizar CreateOrderedEnumerable para realizar una ordenación secundaria en un IOrderedEnumerable<TElement> .The following code example demonstrates how to use CreateOrderedEnumerable to perform a secondary ordering on an IOrderedEnumerable<TElement>.

// Create an array of strings to sort.
string[] fruits = { "apricot", "orange", "banana", "mango", "apple", "grape", "strawberry" };
// First sort the strings by their length.
IOrderedEnumerable<string> sortedFruits2 =
    fruits.OrderBy(fruit => fruit.Length);
// Secondarily sort the strings alphabetically, using the default comparer.
IOrderedEnumerable<string> sortedFruits3 =
    sortedFruits2.CreateOrderedEnumerable<string>(
        fruit => fruit,
        Comparer<string>.Default, false);

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

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

' Create an array of strings to sort.
Dim fruits() As String = {"apricot", "orange", "banana", "mango", "apple", "grape", "strawberry"}
' First sort the strings by their length.
Dim sortedFruits2 As IOrderedEnumerable(Of String) = _
    fruits.OrderBy(Function(ByVal fruit) fruit.Length)
' Secondarily sort the strings alphabetically, using the default comparer.
Dim sortedFruits3 As IOrderedEnumerable(Of String) = _
    sortedFruits2.CreateOrderedEnumerable(Of String)( _
        Function(ByVal fruit) fruit, _
        System.Collections.Generic.Comparer(Of String).Default, _
        False)

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

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

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

Comentarios

La funcionalidad proporcionada por este método es similar a la que proporciona ThenBy o ThenByDescending , dependiendo de si descending es true o false .The functionality provided by this method is like that provided by ThenBy or ThenByDescending, depending on whether descending is true or false. Ambos realizan una ordenación subordinada de una secuencia ya ordenada de tipo IOrderedEnumerable<TElement> .They both perform a subordinate ordering of an already sorted sequence of type IOrderedEnumerable<TElement>.

Se aplica a