I want to create a new array. Let’s say
int[] clickNum = new int[800];
Then I want to do something like clickNum = 2, which would make all array elements starting from clickNum[0] to clickNum[800], set to 2. I know there’s a way to do it by using a loop; but what I am after is just a function or a method to do it.
I suppose you could use
Enumerable.Repeatwhen you initialise the array:It will of course be slower, but unless you’re going to be initiating literally millions of elements, it’ll be fine.
A quick benchmark on my machine showed that initialising 1,000,000 elements using a
forloop took2ms, but usingEnumerable.Repeattook9ms.This page suggests it could be up to 20x slower.