다음을 통해 공유


Queryable.First 메서드

정의

시퀀스의 첫 번째 요소를 반환합니다.

오버로드

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

시퀀스의 첫 번째 요소를 반환합니다.

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

지정된 조건을 충족하는 시퀀스의 첫 번째 요소를 반환합니다.

First<TSource>(IQueryable<TSource>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스의 첫 번째 요소를 반환합니다.

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

형식 매개 변수

TSource

의 요소 형식입니다 source.

매개 변수

source
IQueryable<TSource>

IQueryable<T> 첫 번째 요소를 반환할 값입니다.

반환

TSource

의 첫 번째 요소입니다 source.

특성

예외

sourcenull입니다.

소스 시퀀스가 비어 있습니다.

예제

다음 코드 예제에서는 시퀀스의 첫 번째 요소를 반환하는 데 사용하는 First<TSource>(IQueryable<TSource>) 방법을 보여 줍니다.

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

설명

메서드는 First<TSource>(IQueryable<TSource>) 생성된 제네릭 메서드로 자신을 호출 First<TSource>(IQueryable<TSource>) 하는 것을 나타내는 메서드를 생성 MethodCallExpression 합니다. 그런 다음 매개 변수의 IQueryProvider 속성 source 이 나타내는 메서드에 Provider 전달 MethodCallExpressionExecute<TResult>(Expression) 합니다.

호출 First<TSource>(IQueryable<TSource>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상되는 동작은 .의 첫 번째 요소를 반환하는 것입니다 source.

적용 대상

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

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

지정된 조건을 충족하는 시퀀스의 첫 번째 요소를 반환합니다.

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

형식 매개 변수

TSource

의 요소 형식입니다 source.

매개 변수

source
IQueryable<TSource>

IQueryable<T> 요소를 반환할 값입니다.

predicate
Expression<Func<TSource,Boolean>>

조건에 대한 각 요소를 테스트하는 함수입니다.

반환

TSource

에서 테스트를 predicate통과하는 첫 번째 요소 source 입니다.

특성

예외

source 또는 predicate .입니다 null.

에서 조건을 predicate충족하는 요소가 없습니다.

-또는-

소스 시퀀스가 비어 있습니다.

예제

다음 코드 예제에서는 조건을 충족하는 시퀀스의 첫 번째 요소를 반환하는 데 사용하는 First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 방법을 보여 줍니다.

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

설명

이 메서드에는 형식 인수가 형식 Expression<TDelegate> 중 하나인 형식의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 이 식은 .로 컴파일됩니다 Expression<TDelegate>.

메서드는 First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 생성된 제네릭 메서드로 자신을 호출 First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 하는 것을 나타내는 메서드를 생성 MethodCallExpression 합니다. 그런 다음 매개 변수의 IQueryProvider 속성 source 이 나타내는 메서드에 Provider 전달 MethodCallExpressionExecute<TResult>(Expression) 합니다.

호출 First<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상되는 동작은 지정된 조건을 predicate충족하는 첫 번째 요소를 source 반환하는 것입니다.

적용 대상