0

I'm looking for an equivalent of the C++ std::iota but in .Net (.Net SDK 3.1 LTS compatible)

I want to port this C++ code to .Net

std::array<int, 10> ar;
std::iota(ar.begin(), ar.end(), -4);

This will create an array of int: {-4 -3 -2 -1 0 1 2 3 4 5}

ref: https://en.cppreference.com/w/cpp/algorithm/iota

Mizux
  • 8,222
  • 7
  • 32
  • 48

1 Answers1

1

You may use:

int[] ar = Enumerable.Range(-4, 10).ToArray();

foreach (int value in ar) {
  Console.WriteLine(value);
}

ref: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.range

Mizux
  • 8,222
  • 7
  • 32
  • 48