Queryable.First Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir dizinin ilk öğesini döndürür.
Aşırı Yüklemeler
| First<TSource>(IQueryable<TSource>) |
Bir dizinin ilk öğesini döndürür. |
| First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) |
Belirtilen koşulu karşılayan bir dizinin ilk öğesini döndürür. |
First<TSource>(IQueryable<TSource>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir dizinin ilk öğesini döndürür.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static TSource First(System::Linq::IQueryable<TSource> ^ source);
public static TSource First<TSource> (this System.Linq.IQueryable<TSource> source);
static member First : System.Linq.IQueryable<'Source> -> 'Source
<Extension()>
Public Function First(Of TSource) (source As IQueryable(Of TSource)) As TSource
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
Parametreler
- source
- IQueryable<TSource>
öğesinin IQueryable<T> ilk öğesini döndürmek için.
Döndürülenler
içindeki sourceilk öğe.
Özel durumlar
source, null değeridir.
Kaynak dizisi boş.
Örnekler
Aşağıdaki kod örneği, bir dizideki ilk öğeyi döndürmek için nasıl kullanılacağını First<TSource>(IQueryable<TSource>) gösterir.
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.AsQueryable().First();
Console.WriteLine(first);
/*
This code produces the following output:
9
*/
Dim numbers() As Integer = {9, 34, 65, 92, 87, 435, 3, 54, _
83, 23, 87, 435, 67, 12, 19}
Dim first As Integer = numbers.AsQueryable().First()
MsgBox(first)
' This code produces the following output:
'
' 9
Açıklamalar
yöntemi, First<TSource>(IQueryable<TSource>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran First<TSource>(IQueryable<TSource>) bir oluşturur. Ardından parametresinin MethodCallExpressionExecute<TResult>(Expression) özelliği tarafından temsil edilen yöntemine IQueryProviderProvidersource iletir.
Çağrıyı First<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 ilk öğeyi döndürmesidir source.
Şunlara uygulanır
First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Belirtilen koşulu karşılayan bir dizinin ilk öğesini döndürür.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static TSource First(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, bool> ^> ^ predicate);
public static TSource First<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
static member First : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> 'Source
<Extension()>
Public Function First(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 öğesi.
- predicate
- Expression<Func<TSource,Boolean>>
Bir koşul için her öğeyi test etmek için bir işlev.
Döndürülenler
içindeki source testten geçen ilk öğe.predicate
Özel durumlar
source veya predicate şeklindedir null.
Örnekler
Aşağıdaki kod örneği, bir koşulu karşılayan bir dizinin ilk öğesini döndürmek için nasıl kullanılacağını First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) gösterir.
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
// Get the first number in the array that is greater than 80.
int first = numbers.AsQueryable().First(number => number > 80);
Console.WriteLine(first);
/*
This code produces the following output:
92
*/
Dim numbers() As Integer = {9, 34, 65, 92, 87, 435, 3, 54, _
83, 23, 87, 435, 67, 12, 19}
' Get the first number in the array that is greater than 80.
Dim first As Integer = numbers.AsQueryable().First(Function(number) number > 80)
MsgBox(first)
' This code produces the following output:
'
' 92
Açıklamalar
Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan türünde en az bir parametreye Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.
yöntemi, First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) bir oluşturur. Ardından parametresinin MethodCallExpressionExecute<TResult>(Expression) özelliği tarafından temsil edilen yöntemine IQueryProviderProvidersource iletir.
Çağrıyı First<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ış, tarafından predicatebelirtilen koşulu karşılayan ilk öğesini source döndürmesidir.