Method Sequence
| Edit this page View SourceSequence(int, int)
Generates a sequence of integral numbers within the (inclusive) specified range. If sequence is ascending the step is +1, otherwise -1.
Declaration
public static IEnumerable<int> Sequence(int start, int stop)
Parameters
Type | Name | Description |
---|---|---|
int | start | The value of the first integer in the sequence. |
int | stop | The value of the last integer in the sequence. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An IEnumerable<T> that contains a range of sequential integral numbers. |
Remarks
This operator uses deferred execution and streams its results.
Examples
The following code example demonstrates how to generate a sequence of values using Sequence
.
// Generate a sequence using a sequence function
var result = SuperEnumerable
.Sequence(5, 10);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
result = SuperEnumerable
.Sequence(10, 5);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [5, 6, 7, 8, 9, 10]
// [10, 9, 8, 7, 6, 5]
|
Edit this page
View Source
Sequence(int, int, int)
Generates a sequence of integral numbers within the (inclusive) specified range. An additional parameter specifies the steps in which the integers of the sequence increase or decrease.
Declaration
public static IEnumerable<int> Sequence(int start, int stop, int step)
Parameters
Type | Name | Description |
---|---|---|
int | start | The value of the first integer in the sequence. |
int | stop | The value of the last integer in the sequence. |
int | step | The step to define the next number. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An IEnumerable<T> that contains a range of sequential integral numbers. |
Remarks
When step
is equal to zero, this operator returns an infinite sequence where all elements
are equals to start
. This operator uses deferred execution and streams its results.
Examples
The following code example demonstrates how to generate a sequence of values using Sequence
.
// Generate a sequence using a sequence function
var result = SuperEnumerable
.Sequence(5, 10, 2);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
result = SuperEnumerable
.Sequence(10, 5, -2);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [5, 7, 9]
// [10, 8, 6]