Aracılığıyla paylaş


Queryable.Last Yöntem

Tanım

Bir dizideki son öğeyi döndürür.

Aşırı Yüklemeler

Name Description
Last<TSource>(IQueryable<TSource>)

Bir dizideki son öğeyi döndürür.

Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Belirtilen koşulu karşılayan bir dizinin son öğesini döndürür.

Last<TSource>(IQueryable<TSource>)

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Bir dizideki son öğeyi döndürür.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource Last(System::Linq::IQueryable<TSource> ^ source);
public static TSource Last<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 TSource Last<TSource>(this System.Linq.IQueryable<TSource> source);
static member Last : System.Linq.IQueryable<'Source> -> '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 Last : System.Linq.IQueryable<'Source> -> 'Source
<Extension()>
Public Function Last(Of TSource) (source As IQueryable(Of TSource)) As TSource

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IQueryable<TSource>

IQueryable<T> öğesinin son öğesini döndürmek için.

Döndürülenler

TSource

içindeki son konumdaki sourcedeğer.

Öznitelikler

Özel durumlar

source, null'e eşittir.

Kaynak sıra boş.

Örnekler

Aşağıdaki kod örneği, bir dizinin son öğesini döndürmek için nasıl kullanılacağını Last<TSource>(IQueryable<TSource>) gösterir.

int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
                    83, 23, 87, 67, 12, 19 };

int last = numbers.AsQueryable().Last();

Console.WriteLine(last);

/*
    This code produces the following output:

    19
*/
Dim numbers() As Integer = {9, 34, 65, 92, 87, 435, 3, 54, _
                    83, 23, 87, 67, 12, 19}

Dim last As Integer = numbers.AsQueryable().Last()

MsgBox(last)

' This code produces the following output:
' 19

Açıklamalar

yöntemi, Last<TSource>(IQueryable<TSource>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Last<TSource>(IQueryable<TSource>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)

Çağrıyı Last<TSource>(IQueryable<TSource>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, içindeki sourceson öğeyi döndürmesidir.

Şunlara uygulanır

Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Belirtilen koşulu karşılayan bir dizinin son öğesini döndürür.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource Last(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, bool> ^> ^ predicate);
public static TSource Last<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
[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 TSource Last<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
static member Last : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> '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 Last : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> 'Source
<Extension()>
Public Function Last(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Boolean))) As TSource

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IQueryable<TSource>

öğesi IQueryable<T> döndürülecek.

predicate
Expression<Func<TSource,Boolean>>

Bir koşul için her öğeyi test etmek için bir işlev.

Döndürülenler

TSource

içindeki source son öğesi tarafından predicatebelirtilen testi geçirir.

Öznitelikler

Özel durumlar

source veya predicate şeklindedir null.

içindeki koşulu predicatekarşılayan öğe yok.

-veya-

Kaynak sıra boş.

Örnekler

Aşağıdaki kod örneği, bir koşulu karşılayan bir dizinin son öğesini döndürmek için nasıl kullanılacağını Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) gösterir.

int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
                    83, 23, 87, 67, 12, 19 };

// Get the last number in the array that is greater than 80.
int last = numbers.AsQueryable().Last(num => num > 80);

Console.WriteLine(last);

/*
    This code produces the following output:

    87
*/
Dim numbers() As Integer = {9, 34, 65, 92, 87, 435, 3, 54, _
                    83, 23, 87, 67, 12, 19}

' Get the last number in the array that is greater than 80.
Dim last As Integer = numbers.AsQueryable().Last(Function(num) num > 80)

MsgBox(last)

' This code produces the following output:
' 87

Açıklamalar

Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan en az bir tür parametresine Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.

yöntemi, Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)

Çağrıyı Last<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, içinde tarafından predicatebelirtilen koşulu karşılayan son öğeyi source döndürmesidir.

Şunlara uygulanır