[ACCEPTED]-Simple Sequence Generation?-sequence
.NET 3,5 has Range
too. It's actually Enumerable.Range
and returns 9 IEnumerable<int>
.
The page you linked to is very much out 8 of date - it's talking about 3 as a "future 7 version" and the Enumerable
static class was 6 called Sequence
at one point prior to release.
If 5 you wanted to implement it yourself in C# 2 4 or later, it's easy - here's one:
IEnumerable<int> Range(int count)
{
for (int n = 0; n < count; n++)
yield return n;
}
You can 3 easily write other methods that further 2 filter lists:
IEnumerable<int> Double(IEnumerable<int> source)
{
foreach (int n in source)
yield return n * 2;
}
But as you have 3.5, you can 1 use the extension methods in System.Linq.Enumerable
to do this:
var evens = Enumerable.Range(0, someLimit).Select(n => n * 2);
var r = Enumerable.Range( 1, 200 );
0
Check out System.Linq.Enumerable.Range.
Regarding the second part of 4 your question, what do you mean by "arbitrary 3 lists"? If you can define a function 2 from an int
to the new values, you can use 1 the result of Range with other LINQ methods:
var squares = from i in Enumerable.Range(1, 200)
select i * i;
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.