Queryable.ThenBy Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Esegue un ordinamento successivo degli elementi in una sequenza in ordine crescente.
Overload
| Nome | Descrizione |
|---|---|
| ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) |
Esegue un ordinamento successivo degli elementi in una sequenza in ordine crescente utilizzando un operatore di confronto specificato. |
| ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) |
Esegue un ordinamento successivo degli elementi in una sequenza in ordine crescente in base a una chiave. |
ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>)
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
Esegue un ordinamento successivo degli elementi in una sequenza in ordine crescente utilizzando un operatore di confronto specificato.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IOrderedQueryable<TSource> ^ ThenBy(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> ThenBy<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> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IComparer<'Key> -> System.Linq.IOrderedQueryable<'Source>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IComparer<'Key> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenBy(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)
Parametri di tipo
- TSource
Tipo degli elementi di source.
- TKey
Tipo della chiave restituita dalla funzione rappresentata da keySelector.
Parametri
- source
- IOrderedQueryable<TSource>
Oggetto IOrderedQueryable<T> che contiene elementi da ordinare.
- keySelector
- Expression<Func<TSource,TKey>>
Funzione per estrarre una chiave da ogni elemento.
- comparer
- IComparer<TKey>
Oggetto IComparer<T> da confrontare con le chiavi.
Restituisce
Oggetto IOrderedQueryable<T> i cui elementi sono ordinati in base a una chiave.
- Attributi
Eccezioni
source o o keySelectorcomparer è null.
Commenti
Questo metodo ha almeno un parametro di tipo Expression<TDelegate> il cui argomento di tipo è uno dei Func<T,TResult> tipi . Per questi parametri, è possibile passare un'espressione lambda e verrà compilata in un oggetto Expression<TDelegate>.
Il ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) metodo genera un oggetto MethodCallExpression che rappresenta la chiamata ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) stessa come metodo generico costruito. Passa quindi l'oggetto MethodCallExpression al CreateQuery<TElement>(Expression) metodo dell'oggetto IQueryProvider rappresentato dalla Provider proprietà del source parametro . Il risultato della chiamata CreateQuery<TElement>(Expression) viene eseguito il cast al tipo IOrderedQueryable<T> e restituito.
Il comportamento della query che si verifica come risultato dell'esecuzione di un albero delle espressioni che rappresenta la chiamata ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) dipende dall'implementazione del tipo del source parametro. Il comportamento previsto è che esegue un tipo secondario degli elementi di source in base alla chiave ottenuta richiamando keySelector su ogni elemento di source. Tutti gli ordini di ordinamento stabiliti in precedenza vengono mantenuti. Il comparer parametro viene usato per confrontare i valori di chiave.
Si applica a
ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>)
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
- Origine:
- Queryable.cs
Esegue un ordinamento successivo degli elementi in una sequenza in ordine crescente in base a una chiave.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IOrderedQueryable<TSource> ^ ThenBy(System::Linq::IOrderedQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TKey> ^> ^ keySelector);
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> -> System.Linq.IOrderedQueryable<'Source>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenBy(Of TSource, TKey) (source As IOrderedQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey))) As IOrderedQueryable(Of TSource)
Parametri di tipo
- TSource
Tipo degli elementi di source.
- TKey
Tipo della chiave restituita dalla funzione rappresentata da keySelector.
Parametri
- source
- IOrderedQueryable<TSource>
Oggetto IOrderedQueryable<T> che contiene elementi da ordinare.
- keySelector
- Expression<Func<TSource,TKey>>
Funzione per estrarre una chiave da ogni elemento.
Restituisce
Oggetto IOrderedQueryable<T> i cui elementi sono ordinati in base a una chiave.
- Attributi
Eccezioni
source o keySelector è null.
Esempio
Nell'esempio di codice seguente viene illustrato come usare ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) per eseguire un ordinamento secondario degli elementi in una sequenza.
string[] fruits = { "grape", "passionfruit", "banana", "apple",
"orange", "raspberry", "mango", "blueberry" };
// Sort the strings first by their length and then
// alphabetically by passing the identity selector function.
IEnumerable<string> query =
fruits.AsQueryable()
.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);
foreach (string fruit in query)
Console.WriteLine(fruit);
/*
This code produces the following output:
apple
grape
mango
banana
orange
blueberry
raspberry
passionfruit
*/
Dim fruits() As String = _
{"grape", "passionfruit", "banana", "mango", _
"orange", "raspberry", "apple", "blueberry"}
' Sort the strings first by their length and then
' alphabetically by passing the identity selector function.
Dim query = fruits.AsQueryable() _
.OrderBy(Function(fruit) fruit.Length).ThenBy(Function(fruit) fruit)
' Display the results.
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
MsgBox(output.ToString())
'This code produces the following output:
'apple
'grape
'mango
'banana
'orange
'blueberry
'raspberry
'passionfruit
Commenti
Questo metodo ha almeno un parametro di tipo Expression<TDelegate> il cui argomento di tipo è uno dei Func<T,TResult> tipi . Per questi parametri, è possibile passare un'espressione lambda e verrà compilata in un oggetto Expression<TDelegate>.
Il ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) metodo genera un oggetto MethodCallExpression che rappresenta la chiamata ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) stessa come metodo generico costruito. Passa quindi l'oggetto MethodCallExpression al CreateQuery<TElement>(Expression) metodo dell'oggetto IQueryProvider rappresentato dalla Provider proprietà del source parametro . Il risultato della chiamata CreateQuery<TElement>(Expression) viene eseguito il cast al tipo IOrderedQueryable<T> e restituito.
Il comportamento della query che si verifica come risultato dell'esecuzione di un albero delle espressioni che rappresenta la chiamata ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) dipende dall'implementazione del tipo del source parametro. Il comportamento previsto è che esegue un tipo secondario degli elementi di source in base alla chiave ottenuta richiamando keySelector su ogni elemento di source. Tutti gli ordini di ordinamento stabiliti in precedenza vengono mantenuti.