IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey> Yöntem

Tanım

Bir anahtara göre öğesinin IOrderedEnumerable<TElement> öğeleri üzerinde sonraki sıralamayı gerçekleştirir.

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)

Tür Parametreleri

TKey

tarafından keySelectorüretilen anahtarın türü.

Parametreler

keySelector
Func<TElement,TKey>

Func<T,TResult> Her öğenin anahtarını ayıklamak için kullanılır.

comparer
IComparer<TKey>

Döndürülen IComparer<T> dizideki yerleştirme anahtarlarını karşılaştırmak için kullanılır.

descending
Boolean

true öğeleri azalan düzende sıralamak için; false öğeleri artan düzende sıralamak için.

Döndürülenler

Öğeleri IOrderedEnumerable<TElement> bir anahtara göre sıralanmış olan.

Örnekler

Aşağıdaki kod örneği, üzerinde ikincil sıralama IOrderedEnumerable<TElement>gerçekleştirmek için nasıl kullanılacağını CreateOrderedEnumerable gösterir.

// 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

Açıklamalar

Bu yöntem tarafından sağlanan işlevsellik, veya falseolmasına descending bağlı olarak veya ThenByDescendingtarafından ThenBy sağlanan işleve benzer.true Her ikisi de türüne IOrderedEnumerable<TElement>ait önceden sıralanmış bir sıranın alt sıralamasını gerçekleştirir.

Şunlara uygulanır