C# Array CreateInstance(Type, Int32, Int32)
Description
Array CreateInstance(Type, Int32, Int32)
creates a
two-dimensional Array of the specified Type and dimension lengths, with
zero-based indexing.
Syntax
Array.CreateInstance(Type, Int32, Int32)
has the following syntax.
public static Array CreateInstance(
Type elementType,//w ww. j av a 2 s.co m
int length1,
int length2
)
Parameters
Array.CreateInstance(Type, Int32, Int32)
has the following parameters.
elementType
- The Type of the Array to create.length1
- The size of the first dimension of the Array to create.length2
- The size of the second dimension of the Array to create.
Returns
Array.CreateInstance(Type, Int32, Int32)
method returns A new two-dimensional Array of the specified Type with the specified length
for each dimension, using zero-based indexing.
Example
The following code example shows how to create and initialize a two-dimensional Array.
//from w w w. ja v a 2 s.co 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 );
}
}
The code above generates the following result.