Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get alternate numbers using Enumerable.Range?

If Start=0 and Count=10 then how to get the alternate values using Enumerable.Range() the out put should be like { 0, 2, 4, 6, 8 }

and if Start=1 and Count=10 then { 1, 3, 5, 7, 9 }

The continuous value can be get like

var a = Enumerable.Range(0,10).ToList();

but how to get the alternate values?

like image 287
Thorin Oakenshield Avatar asked Nov 10 '10 08:11

Thorin Oakenshield


1 Answers

Halving the number of items that Range should generate (its second parameter) and then doubling the resulting values will give both the correct number of items and ensure an increment of 2.

Enumerable.Range(0,5).Select(x => x * 2)
like image 78
leppie Avatar answered Oct 01 '22 12:10

leppie