Create a two-dimensional Array of the specified Type and dimension, with zero-based indexing in CSharp
Description
The following code shows how to create a two-dimensional Array of the specified Type and dimension, with zero-based indexing.
Example
/*w w w.ja va2 s. c o m*/
using System;
public class SamplesArray {
public static void Main() {
Array my2DArray=Array.CreateInstance( typeof(String), 2, 3 );
for ( int i = my2DArray.GetLowerBound(0); i <= my2DArray.GetUpperBound(0); i++ )
for ( int j = my2DArray.GetLowerBound(1); j <= my2DArray.GetUpperBound(1); j++ ){
my2DArray.SetValue( "aaa" + i + j, i, j );
Console.WriteLine("aaa" + i + j);
}
}
}
The code above generates the following result.