Hamza Nasab
Hamza Nasab

Reputation: 122

C# Setup the amount of dimensions in an array in runtime

I want to do something like this

int amountOfDimensions = 3;
Array a = new Array(3);

but of course that is not a thing in C#,
but is there's something that do the same thing ?

Upvotes: 0

Views: 41

Answers (1)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

Try Array.CreateInstance, e.g.

// array of int with 3 dimensions with correspondent lengths 2, 3 and 4:
// i.e. result will be int[2, 3, 4]
var result = Array.CreateInstance(typeof(int), 2, 3, 4);

Upvotes: 4

Related Questions