In C#, I need to pass a multi-dimensional integer array to a method, but the actual dimension of this array is unknown until run time, how do I achieve this?
For example, the input can be:
- {1,2,3}
- {1,2,{1}}
- {1{1,2,3,}2,2,{6,{4,{1,2,3,4}}}}
Basically, I am trying to flatten a multi-dimensional array. For example, the input of my method is: {1{1,2,3,}2,2,{6,{4,{1,2,3,4}}}}, the output will be {1,1,2,3,2,2,6,4,1,2,3,4}
I have come up with the following unfinished code block:
public void Recursive(multiple-dimension-integer-array)
{
foreach (var element in multiple-dimension-integer-array)
{
if (element is int)
result.Add(element);
else Recursive(element);
}
}