Class RangeExtensions
Extension methods for
Inheritance
Namespace: X10D.Core
Assembly: X10D.dll
Syntax
public static class RangeExtensions : object
Methods
| Improve this Doc View SourceGetEnumerator(Range)
Allows the ability to use a for
loop to iterate over the indices of a
Declaration
public static RangeEnumerator GetEnumerator(this Range range)
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range whose indices over which will be enumerated. |
Returns
Type | Description |
---|---|
RangeEnumerator | A RangeEnumerator that will enumerate over the indices of |
Remarks
This method aims to implement Python-esque for loops in C# by taking advantage of the language syntax used to define
a ^
operator, or by providing an
Examples
The following example counts from 0 to 10 inclusive:
foreach (var i in 0..10)
{
Console.WriteLine(i);
}
To use negative bounds, use the ^
operator. The following example counts from -5 to 5 inclusive:
foreach (var i in ^5..5)
{
Console.WriteLine(i);
}
Decrementing enumeration is supported. The following example counts from 5 to -5 inclusive:
foreach (var i in 5..^5)
{
Console.WriteLine(i);
}