Enumerable.Take 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Take<TSource>(IEnumerable<TSource>, Int32) |
시퀀스 시작부터 지정된 수의 연속 요소를 반환합니다. |
| Take<TSource>(IEnumerable<TSource>, Range) |
시퀀스에서 지정된 연속 요소 범위를 반환합니다. |
Take<TSource>(IEnumerable<TSource>, Int32)
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
시퀀스 시작부터 지정된 수의 연속 요소를 반환합니다.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ Take(System::Collections::Generic::IEnumerable<TSource> ^ source, int count);
public static System.Collections.Generic.IEnumerable<TSource> Take<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int count);
static member Take : seq<'Source> * int -> seq<'Source>
<Extension()>
Public Function Take(Of TSource) (source As IEnumerable(Of TSource), count As Integer) As IEnumerable(Of TSource)
형식 매개 변수
- TSource
의 요소 형식입니다 source.
매개 변수
- source
- IEnumerable<TSource>
요소를 반환할 시퀀스입니다.
- count
- Int32
반환할 요소의 수입니다.
반품
IEnumerable<T> 입력 시퀀스의 시작부터 지정된 개수의 요소를 포함하는 값입니다.
예외
source은 null입니다.
예제
다음 코드 예제에서는 시퀀스의 시작 부분부터(정렬된 후) 요소를 반환하는 데 사용하는 Take 방법을 보여 줍니다.
int[] grades = { 59, 82, 70, 56, 92, 98, 85 };
IEnumerable<int> topThreeGrades =
grades.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
*/
' Create an array of Integer values that represent grades.
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}
' Get the highest three grades by first sorting
' them in descending order and then taking the
' first three values.
Dim topThreeGrades As IEnumerable(Of Integer) =
grades _
.OrderByDescending(Function(grade) grade) _
.Take(3)
' Display the results.
Dim output As New System.Text.StringBuilder("The top three grades are:" & vbCrLf)
For Each grade As Integer In topThreeGrades
output.AppendLine(grade)
Next
Console.WriteLine(output.ToString())
' This code produces the following output:
'
' The top three grades are:
' 98
' 92
' 85
설명
이 메서드는 지연된 실행을 사용하여 구현됩니다. 즉시 반환 값은 작업을 수행하는 데 필요한 모든 정보를 저장하는 개체입니다. 이 메서드가 나타내는 쿼리는 해당 GetEnumerator 메서드를 직접 호출하거나 C#의 foreach 또는 Visual Basic For Each 사용하여 개체가 열거될 때까지 실행되지 않습니다.
Take요소가 생성되거나 source 더 이상 요소가 포함되지 않을 때까지 count 요소를 열거 source 하고 생성합니다. 요소 count수를 초과하면 source 모든 요소가 source 반환됩니다.
0 count 보다 작거나 같으면 source 열거되지 않고 빈 IEnumerable<T> 항목이 반환됩니다.
및 Take 메서드는 Skip 기능 보완입니다. 컬렉션 시퀀스와 coll 정수가 지정되면 결과를 n 연결하고 coll.Take(n)coll.Skip(n).coll
Visual Basic 쿼리 식 구문에서 Take 절은 Take 호출로 변환됩니다.
추가 정보
Visual Basic)
적용 대상
Take<TSource>(IEnumerable<TSource>, Range)
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
- Source:
- Take.cs
시퀀스에서 지정된 연속 요소 범위를 반환합니다.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ Take(System::Collections::Generic::IEnumerable<TSource> ^ source, Range range);
public static System.Collections.Generic.IEnumerable<TSource> Take<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, Range range);
static member Take : seq<'Source> * Range -> seq<'Source>
<Extension()>
Public Function Take(Of TSource) (source As IEnumerable(Of TSource), range As Range) As IEnumerable(Of TSource)
형식 매개 변수
- TSource
의 요소 형식입니다 source.
매개 변수
- source
- IEnumerable<TSource>
요소를 반환할 시퀀스입니다.
- range
- Range
반환할 요소의 범위로, 시퀀스의 시작 또는 끝에서 시작 및 끝 인덱스가 있습니다.
반품
IEnumerable<T> 시퀀스에서 지정된 요소 범위를 포함하는 항목 source 입니다.
예외
source은 null입니다.
설명
이 메서드는 지연된 실행을 사용하여 구현됩니다. 즉시 반환 값은 작업을 수행하는 데 필요한 모든 정보를 저장하는 개체입니다. 이 메서드가 나타내는 쿼리는 해당 GetEnumerator 메서드를 직접 호출하거나 C#의 foreach 또는 Visual Basic For Each 사용하여 개체가 열거될 때까지 실행되지 않습니다.
Take인덱스가 지정된 range요소에 source 속하는 요소를 열거하고 생성합니다.