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
| Name | Description |
|---|---|
| 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
- 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);
[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 First<TSource>(this System.Linq.IQueryable<TSource> source);
static member First : 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 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.
- Öznitelikler
Özel durumlar
source, null'e eşittir.
Kaynak sıra 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 özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Ç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
- 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);
[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 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
[<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 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.
- 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 testini ileten ilk öğe.predicate
- Öznitelikler
Ö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 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, 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 özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Ç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.