How to get alternate numbers using Enumerable.Range?

前端 未结 5 1284
梦谈多话
梦谈多话 2021-02-07 09:24

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 }

5条回答
  •  猫巷女王i
    2021-02-07 09:41

    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)
    

提交回复
热议问题