Enumerable.Range(Int32, Int32) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirtilen aralık içinde tam sayı dizisi oluşturur.
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)
Parametreler
- start
- Int32
Dizideki ilk tamsayının değeri.
- count
- Int32
Oluşturulacak sıralı tamsayı sayısı.
Döndürülenler
Sıralı tam sayı aralığı içeren Visual Basic C# veya IEnumerable(Of Int32)IEnumerable<Int32>.
Özel durumlar
Örnekler
Aşağıdaki kod örneği, bir değer dizisi oluşturmak için nasıl kullanılacağını Range gösterir.
// 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
Açıklamalar
Bu yöntem ertelenen yürütme kullanılarak uygulanır. Hemen dönüş değeri, eylemi gerçekleştirmek için gereken tüm bilgileri depolayan bir nesnedir. Bu yöntemle temsil edilen sorgu, nesne doğrudan GetEnumerator yöntemini çağırarak veya C# içinde foreach veya Visual Basic'de For Each kullanılarak numaralandırılana kadar yürütülür.