Creating 100 variables

124 Views Asked by At

So I created an array with 100 variables using Enumerable.Range. The data type is limited to Int32.

Problem

  • How can I create the same array with SByte?

  • Am I right in thinking I would need to use a loop to create and index the variables?

I have looked around online and most results touch on declaring counting variables for the loop but not using a loop to declare variables

1

There are 1 best solutions below

0
Tim Schmelter On BEST ANSWER

Just cast them:

SByte[] array = Enumerable.Range(0, 100).Select(i => (SByte) i).ToArray();

note that SByte is not cls compliant, you might want to use short instead.