Enumerable.Range(Int32, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 범위 내에서 정수 시퀀스를 생성합니다.
public:
static System::Collections::Generic::IEnumerable<int> ^ Range(int start, int count);
public static System.Collections.Generic.IEnumerable<int> Range(int start, int count);
static member Range : int * int -> seq<int>
Public Function Range (start As Integer, count As Integer) As IEnumerable(Of Integer)
매개 변수
- start
- Int32
시퀀스의 첫 번째 정수 값입니다.
- count
- Int32
생성할 순차 정수 수입니다.
반품
C#의 IEnumerable<Int32> 또는 순차적 정수 범위를 포함하는 Visual Basic IEnumerable(Of Int32).
예외
예제
다음 코드 예제에서는 값 시퀀스를 생성하는 데 사용하는 Range 방법을 보여 줍니다.
// Generate a sequence of integers from 1 to 10
// and then select their squares.
IEnumerable<int> squares = Enumerable.Range(1, 10).Select(x => x * x);
foreach (int num in squares)
{
Console.WriteLine(num);
}
/*
This code produces the following output:
1
4
9
16
25
36
49
64
81
100
*/
' Generate a sequence of integers from 1 to 10
' and project their squares.
Dim squares As IEnumerable(Of Integer) =
Enumerable.Range(1, 10).Select(Function(x) x * x)
Dim output As New System.Text.StringBuilder
For Each num As Integer In squares
output.AppendLine(num)
Next
' Display the output.
Console.WriteLine(output.ToString())
' This code produces the following output:
'
' 1
' 4
' 9
' 16
' 25
' 36
' 49
' 64
' 81
' 100
설명
이 메서드는 지연된 실행을 사용하여 구현됩니다. 즉시 반환 값은 작업을 수행하는 데 필요한 모든 정보를 저장하는 개체입니다. 이 메서드가 나타내는 쿼리는 해당 GetEnumerator 메서드를 직접 호출하거나 C#의 foreach 또는 Visual Basic For Each 사용하여 개체가 열거될 때까지 실행되지 않습니다.