IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey> Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Wykonuje kolejną kolejność na elementach elementu IOrderedEnumerable<TElement> zgodnie z kluczem.
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)
Parametry typu
- TKey
Typ klucza wygenerowanego przez keySelector
program .
Parametry
- keySelector
- Func<TElement,TKey>
Element Func<T,TResult> używany do wyodrębniania klucza dla każdego elementu.
- comparer
- IComparer<TKey>
Służy IComparer<T> do porównywania kluczy do umieszczania w zwróconej sekwencji.
- descending
- Boolean
true
aby posortować elementy w kolejności malejącej; false
aby posortować elementy w kolejności rosnącej.
Zwraca
Element IOrderedEnumerable<TElement> , którego elementy są sortowane według klucza.
Przykłady
W poniższym przykładzie kodu pokazano, jak wykonać CreateOrderedEnumerable kolejność pomocniczą w obiekcie 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
Uwagi
Funkcjonalność udostępniana przez tę metodę jest podobna do funkcji dostarczanej przez ThenBy program lub ThenByDescending, w zależności od tego, czy descending
element to true
, czy false
. Obaj wykonują podrzędne porządkowanie już posortowanej sekwencji typu IOrderedEnumerable<TElement>.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla