4 ms·
> LINQ, to generate only every 4th number in a range Maybe something like this? Enumerable.Range(0,49).Select(x => 4*x + 1)
by 369548684892826 4y ago
> LINQ, to generate only every 4th number in a range
Maybe something like this?
Enumerable.Range(0,49).Select(x => 4*x + 1)
- Jtsummers 4y agoYeah, that would work, throw it before the Where clause and change 49. Range here doesn't specify a stopping point, but a count of generated values (this makes it not quite the same as Python's range). So you'd want: Enumerable.Range(0,13).Select(x => 4 * x + 1).Where((e, i) => i % 3 == 0).Skip(2) And that's equivalent to the original, short of writing a MyRange that combines the first Range and Select. Still an awful lot of work for generating 3 numbers.