Dynamically created jagged "rectangle" array

Posted by gagar1n on Stack Overflow See other posts from Stack Overflow or by gagar1n
Published on 2010-03-16T22:01:30Z Indexed on 2010/03/16 22:11 UTC
Read the original article Hit count: 179

Filed under:
|
|

In my project I have a lot of code like this:

int[][] a = new int[firstDimension][];
for (int i=0; i<firstDimension; i++)
{
  a[i] = new int[secondDimension];
}

Types of elements are different.

Is there any way of writing a method like

createArray(typeof(int), firstDimension, secondDimension);

and getting new int[firstDimension][secondDimension]?

Once again, type of elements is known only at runtime.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#