F# has sequences that allows to create sequences:
seq { 0 .. 10 }
Create sequence of numbers from 0 to 10.
Is there something similar in C#?
F# has sequences that allows to create sequences:
seq { 0 .. 10 }
Create sequence of numbers from 0 to 10.
Is there something similar in C#?
Linq projection with the rarely used indexer overload (i):
I prefer this method for its flexibilty.
For example, if I want evens:
Or if I want 5 minute increments of an hour:
Or strings:
If you want to enumerate a sequence of numbers (
IEnumerable<int>
) from0
to a variableend
, then tryIn explanation, to get a sequence of numbers from 0 to 1000, you want the sequence to start at 0 (remembering that there are 1001 numbers between 0 and 1000, inclusive).
If you want an unlimited linear series, you could write a function like
which you could use like
If you want a function you can call repeatedly to generate incrementing numbers, perhaps you want somthing like.
When you call
Seq()
it will return the next order number and increment the counter.Generates a sequence of integral numbers within a specified range.
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx
You could create a simple function. This would work for a more complicated sequence. Otherwise the
Enumerable.Range
should do.My implementation:
You can use
Enumerable.Range(0, 10);
. Example:MSDN page here.