IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey> Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Effectue un classement ultérieur sur les éléments d’une IOrderedEnumerable<TElement> clé.
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);
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)
Paramètres de type
- TKey
Type de la clé produite par keySelector.
Paramètres
- keySelector
- Func<TElement,TKey>
Utilisé Func<T,TResult> pour extraire la clé de chaque élément.
- comparer
- IComparer<TKey>
IComparer<T> Utilisé pour comparer les clés pour le placement dans la séquence retournée.
- descending
- Boolean
true pour trier les éléments dans l’ordre décroissant ; false pour trier les éléments dans l’ordre croissant.
Retours
Dont IOrderedEnumerable<TElement> les éléments sont triés en fonction d’une clé.
Exemples
L’exemple de code suivant montre comment effectuer CreateOrderedEnumerable un classement secondaire sur un 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
Remarques
La fonctionnalité fournie par cette méthode est semblable à celle fournie par ThenBy ou ThenByDescending, selon qu’elle descending est true ou false. Ils effectuent tous deux un ordre subordonné d’une séquence de type IOrderedEnumerable<TElement>déjà triée.