다음을 통해 공유


Queryable.Take 메서드

정의

오버로드

Name Description
Take<TSource>(IQueryable<TSource>, Int32)

시퀀스 시작부터 지정된 수의 연속 요소를 반환합니다.

Take<TSource>(IQueryable<TSource>, Range)

시퀀스에서 지정된 연속 요소 범위를 반환합니다.

Take<TSource>(IQueryable<TSource>, Int32)

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

시퀀스 시작부터 지정된 수의 연속 요소를 반환합니다.

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

형식 매개 변수

TSource

의 요소 형식입니다 source.

매개 변수

source
IQueryable<TSource>

요소를 반환할 시퀀스입니다.

count
Int32

반환할 요소의 수입니다.

반환

IQueryable<TSource>

IQueryable<T> 시작부터 지정된 수의 요소가 들어 있는 값입니다source.

특성

예외

sourcenull입니다.

예제

다음 코드 예제에서는 시퀀스의 시작부터 요소를 반환하는 데 사용하는 Take<TSource>(IQueryable<TSource>, Int32) 방법을 보여 줍니다.

int[] grades = { 59, 82, 70, 56, 92, 98, 85 };

// Sort the grades in descending order and take the first three.
IEnumerable<int> topThreeGrades =
    grades.AsQueryable().OrderByDescending(grade => grade).Take(3);

Console.WriteLine("The top three grades are:");
foreach (int grade in topThreeGrades)
    Console.WriteLine(grade);

/*
    This code produces the following output:

    The top three grades are:
    98
    92
    85
*/
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Sort the grades in descending order and take the first three.
Dim topThreeGrades = _
    grades.AsQueryable().OrderByDescending(Function(grade) grade).Take(3)

Dim output As New System.Text.StringBuilder
output.AppendLine("The top three grades are:")
For Each grade As Integer In topThreeGrades
    output.AppendLine(grade)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:

' The top three grades are:
' 98
' 92
' 85

설명

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

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

적용 대상

Take<TSource>(IQueryable<TSource>, Range)

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

시퀀스에서 지정된 연속 요소 범위를 반환합니다.

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

형식 매개 변수

TSource

의 요소 형식입니다 source.

매개 변수

source
IQueryable<TSource>

요소를 반환할 시퀀스입니다.

range
Range

반환할 요소의 범위이며 시작 또는 끝부터 시작 및 끝 인덱스가 있습니다.

반환

IQueryable<TSource>

IQueryable<T> 시퀀스에서 지정된 range 요소가 들어 있는 항목 source 입니다.

특성

예외

sourcenull입니다.

적용 대상