Enumerable.Range(轉)

  • 52
  • 0

Enumerable.Range

https://dotblogs.com.tw/rainmaker/2013/04/24/102208

// Generate a sequence of integers from 1 to 10 
// and then select their squares.
IEnumerable<int> squares = Enumerable.Range(1, 10).Select(x => x * x);

foreach (int num in squares)
{
    Console.WriteLine(num);
}

/*
 This code produces the following output:

 1
 4
 9
 16
 25
 36
 49
 64
 81
 100
*/

https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.range?view=netframework-4.7.2