Queryable.ThenByDescending メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
シーケンス内の後続の要素を降順で配置します。
オーバーロード
ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) |
キーに従って、シーケンス内の後続の要素を降順で配置します。 |
ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) |
指定された比較子を使用して、シーケンス内の後続の要素を降順で配置します。 |
ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>)
キーに従って、シーケンス内の後続の要素を降順で配置します。
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IOrderedQueryable<TSource> ^ ThenByDescending(System::Linq::IOrderedQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TKey> ^> ^ keySelector);
public static System.Linq.IOrderedQueryable<TSource> ThenByDescending<TSource,TKey> (this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);
static member ThenByDescending : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenByDescending(Of TSource, TKey) (source As IOrderedQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey))) As IOrderedQueryable(Of TSource)
型パラメーター
- TSource
source
の要素の型。
- TKey
keySelector
で表された関数によって返されるキーの型。
パラメーター
- source
- IOrderedQueryable<TSource>
並べ替える要素を格納している IOrderedQueryable<T>。
- keySelector
- Expression<Func<TSource,TKey>>
各要素からキーを抽出する関数。
戻り値
- IOrderedQueryable<TSource>
要素がキーに従って降順に並べ替えられている IOrderedQueryable<T>。
例外
source
または keySelector
が null
です。
注釈
このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターの場合は、ラムダ式を渡すと、コンパイルされます Expression<TDelegate>。
このメソッドは ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) 、 MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) 自体を表す a を生成します。 次に、パラメーターのMethodCallExpressionCreateQuery<TElement>(Expression)プロパティsource
で表されるメソッドIQueryProviderにProvider渡します。 呼び出し CreateQuery<TElement>(Expression) の結果は型 IOrderedQueryable<T> にキャストされ、返されます。
呼び出し ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) を表す式ツリーを実行した結果として発生するクエリ動作は、パラメーターの型の source
実装によって異なります。 予期される動作は、の各要素 source
で呼び出 keySelector
すことによって取得されたキーに基づいて、降順で要素の source
二次的な並べ替えを実行することです。 以前に確立されたすべての並べ替え順序は保持されます。
適用対象
ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>)
指定された比較子を使用して、シーケンス内の後続の要素を降順で配置します。
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IOrderedQueryable<TSource> ^ ThenByDescending(System::Linq::IOrderedQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TKey> ^> ^ keySelector, System::Collections::Generic::IComparer<TKey> ^ comparer);
public static System.Linq.IOrderedQueryable<TSource> ThenByDescending<TSource,TKey> (this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey> comparer);
public static System.Linq.IOrderedQueryable<TSource> ThenByDescending<TSource,TKey> (this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
static member ThenByDescending : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IComparer<'Key> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenByDescending(Of TSource, TKey) (source As IOrderedQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey)), comparer As IComparer(Of TKey)) As IOrderedQueryable(Of TSource)
型パラメーター
- TSource
source
の要素の型。
- TKey
keySelector
関数によって返されるキーの型。
パラメーター
- source
- IOrderedQueryable<TSource>
並べ替える要素を格納している IOrderedQueryable<T>。
- keySelector
- Expression<Func<TSource,TKey>>
各要素からキーを抽出する関数。
- comparer
- IComparer<TKey>
キーを比較する IComparer<T>。
戻り値
- IOrderedQueryable<TSource>
要素がキーに従って降順に並べ替えられているコレクション。
例外
source
、keySelector
、または comparer
は、null
です。
例
次のコード例では、カスタム 比較子を使用 ThenByDescending<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) して、要素の 2 次順序を降順で実行する方法を示します。
public class CaseInsensitiveComparer : IComparer<string>
{
public int Compare(string x, string y)
{
return string.Compare(x, y, true);
}
}
public static void ThenByDescendingEx1()
{
string[] fruits =
{ "apPLe", "baNanA", "apple", "APple", "orange", "BAnana", "ORANGE", "apPLE" };
// Sort the strings first ascending by their length and
// then descending using a custom case insensitive comparer.
IEnumerable<string> query =
fruits.AsQueryable()
.OrderBy(fruit => fruit.Length)
.ThenByDescending(fruit => fruit, new CaseInsensitiveComparer());
foreach (string fruit in query)
Console.WriteLine(fruit);
}
/*
This code produces the following output:
apPLe
apple
APple
apPLE
orange
ORANGE
baNanA
BAnana
*/
Class CaseInsensitiveComparer
Implements IComparer(Of String)
Function Compare(ByVal x As String, ByVal y As String) As Integer _
Implements IComparer(Of String).Compare
' Compare values and ignore case.
Return String.Compare(x, y, True)
End Function
End Class
Sub ThenByDescendingEx1()
Dim fruits() As String = _
{"apPLe", "baNanA", "apple", "APple", "orange", "BAnana", "ORANGE", "apPLE"}
' Sort the strings first ascending by their length and
' then descending by using a custom case insensitive comparer.
Dim query = fruits.AsQueryable() _
.OrderBy(Function(fruit) fruit.Length) _
.ThenByDescending(Function(fruit) fruit, New CaseInsensitiveComparer())
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
' Display the results.
MsgBox(output.ToString())
End Sub
' This code produces the following output:
' apPLe
' apple
' APple
' apPLE
' orange
' ORANGE
' baNanA
' BAnana
注釈
このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターの場合は、ラムダ式を渡すと、コンパイルされます Expression<TDelegate>。
このメソッドは ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) 、 MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) 自体を表す a を生成します。 次に、パラメーターのMethodCallExpressionCreateQuery<TElement>(Expression)プロパティsource
で表されるメソッドIQueryProviderにProvider渡します。 呼び出し CreateQuery<TElement>(Expression) の結果は型 IOrderedQueryable<T> にキャストされ、返されます。
呼び出し ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) を表す式ツリーを実行した結果として発生するクエリ動作は、パラメーターの型の source
実装によって異なります。 予期される動作は、の各要素 source
で呼び出 keySelector
すことによって取得されたキーに基づいて、降順で要素の source
二次的な並べ替えを実行することです。 以前に確立されたすべての並べ替え順序は保持されます。 この comparer
パラメーターは、キー値の比較に使用されます。