C# Array CreateInstance(Type, Int32, Int32, Int32)
Description
Array CreateInstance(Type, Int32, Int32, Int32)
creates
a three-dimensional Array of the specified Type and dimension lengths,
with zero-based indexing.
Syntax
Array.CreateInstance(Type, Int32, Int32, Int32)
has the following syntax.
public static Array CreateInstance(
Type elementType,//from w w w . ja v a 2 s . c o m
int length1,
int length2,
int length3
)
Parameters
Array.CreateInstance(Type, Int32, 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.length3
- The size of the third dimension of the Array to create.
Returns
Array.CreateInstance(Type, Int32, Int32, Int32)
method returns A new three-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 three-dimensional Array.
//from w w w . ja va 2s.c o m
using System;
public class SamplesArray {
public static void Main() {
Array my3DArray=Array.CreateInstance( typeof(Object), 2, 3, 4 );
for ( int i = my3DArray.GetLowerBound(0); i <= my3DArray.GetUpperBound(0); i++ )
for ( int j = my3DArray.GetLowerBound(1); j <= my3DArray.GetUpperBound(1); j++ )
for ( int k = my3DArray.GetLowerBound(2); k <= my3DArray.GetUpperBound(2); k++ )
my3DArray.SetValue( "abc", i, j, k );
}
}
The code above generates the following result.