Queryable.Reverse<TSource>(IQueryable<TSource>) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginversi urutan elemen secara berurutan.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<TSource> ^ Reverse(System::Linq::IQueryable<TSource> ^ source);
public static System.Linq.IQueryable<TSource> Reverse<TSource>(this System.Linq.IQueryable<TSource> 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.")]
public static System.Linq.IQueryable<TSource> Reverse<TSource>(this System.Linq.IQueryable<TSource> source);
static member Reverse : System.Linq.IQueryable<'Source> -> System.Linq.IQueryable<'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 Reverse : System.Linq.IQueryable<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Reverse(Of TSource) (source As IQueryable(Of TSource)) As IQueryable(Of TSource)
Jenis parameter
- TSource
Jenis elemen source.
Parameter
- source
- IQueryable<TSource>
Urutan nilai untuk dibalik.
Mengembalikan
Elemen IQueryable<T> yang sesuai dengan urutan input dalam urutan terbalik.
- Atribut
Pengecualian
source adalah null.
Contoh
Contoh kode berikut menunjukkan cara menggunakan Reverse<TSource>(IQueryable<TSource>) untuk membalikkan urutan elemen dalam array.
char[] apple = { 'a', 'p', 'p', 'l', 'e' };
// Reverse the order of the characters in the collection.
IQueryable<char> reversed = apple.AsQueryable().Reverse();
foreach (char chr in reversed)
Console.Write(chr + " ");
Console.WriteLine();
/*
This code produces the following output:
e l p p a
*/
Dim appleLetters As New List(Of Char)(New Char() _
{"a"c, "p"c, "p"c, "l"c, "e"c})
' Reverse the order of the characters in the collection.
Dim reversed As IQueryable(Of Char) = _
appleLetters.AsQueryable().Reverse()
Dim output As New System.Text.StringBuilder
For Each chr As Char In reversed
output.Append(chr & " ")
Next
' Display the output.
MsgBox(output.ToString())
' This code produces the following output:
'
' e l p p a
Keterangan
Metode ini Reverse<TSource>(IQueryable<TSource>) menghasilkan MethodCallExpression yang mewakili pemanggilan Reverse<TSource>(IQueryable<TSource>) dirinya sebagai metode generik yang dibangun. Kemudian meneruskan MethodCallExpression ke CreateQuery<TElement>(Expression) metode yang diwakili IQueryProvider oleh Provider properti source parameter.
Perilaku kueri yang terjadi sebagai akibat dari menjalankan pohon ekspresi yang mewakili panggilan Reverse<TSource>(IQueryable<TSource>) tergantung pada implementasi jenis source parameter. Perilaku yang diharapkan adalah bahwa ia membalikkan urutan elemen di source.