How to get alternate numbers using Enumerable.Range?

前端 未结 5 1261
梦谈多话
梦谈多话 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条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 09:24

    Enumerable.Range(0, 10).Where(i => i % 2 == 0); // { 0, 2, 4, 6, 8 }
    Enumerable.Range(0, 10).Where(i => i % 2 != 0); // { 1, 3, 5, 7, 9 }
    

提交回复
热议问题