IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey> 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
IOrderedEnumerable<TElement>의 요소를 키에 따라 후속 정렬합니다.
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)
형식 매개 변수
- TKey
keySelector
가 생성하는 키의 형식입니다.
매개 변수
- keySelector
- Func<TElement,TKey>
각 요소의 키를 추출하는 데 사용되는 Func<T,TResult>입니다.
- comparer
- IComparer<TKey>
반환되는 시퀀스에 배치하기 위해 키를 비교하는 데 사용되는 IComparer<T>입니다.
- descending
- Boolean
요소를 내림차순으로 정렬하려면 true
이고, 요소를 오름차순으로 정렬하려면 false
입니다.
반환
요소가 키에 따라 정렬된 IOrderedEnumerable<TElement>입니다.
예제
다음 코드 예제에서는 를 사용하여 CreateOrderedEnumerable 에서 보조 순서를 수행하는 방법을 보여 줍니다 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
설명
이 메서드에서 제공하는 기능은 가 또는 인지 true
descending
false
에 따라 또는 ThenByDescending에서 제공하는 ThenBy 기능과 같습니다. 둘 다 이미 정렬된 형식 시퀀스의 하위 순서를 수행합니다 IOrderedEnumerable<TElement>.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기