Is there an “upto” method in C#?

前端 未结 6 1785
攒了一身酷
攒了一身酷 2021-02-18 14:31

Here\'s a bit of code which prints out the squares of the numbers from 0 to 9:

for (int i = 0; i < 10; i++)
    Console.WriteLine(i*i);

Doin

6条回答
  •  情话喂你
    2021-02-18 14:54

    wanna do it in one line ? here it goes:

    Enumerable.Range(0, 9).Select(i => i * i).ToList().ForEach(j=>Console.WriteLine("%d",j));
    

提交回复
热议问题