Enumerable.Range(Int32, Int32) 메서드

정의

지정된 범위 내의 정수 시퀀스를 생성합니다.

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

생성할 순차적 정수의 개수입니다.

반환

IEnumerable<Int32> 순차 정수 범위를 포함하는 C# 또는 IEnumerable(Of Int32) Visual Basic의 입니다.

예외

count 가 0보다 작습니다.

또는

start + count -1은 Int32.MaxValue보다 큽습니다.

예제

다음 코드 예제에서는 를 사용하여 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# 또는 For Each Visual Basic에서 를 사용하여 foreach 개체를 열거할 때까지 실행되지 않습니다.

적용 대상