C# Array CreateInstance(Type, Int32)
Description
Array CreateInstance(Type, Int32)
creates a one-dimensional
Array of the specified Type and length, with zero-based indexing.
Syntax
Array.CreateInstance(Type, Int32)
has the following syntax.
public static Array CreateInstance(
Type elementType,
int length
)
Parameters
Array.CreateInstance(Type, Int32)
has the following parameters.
elementType
- The Type of the Array to create.length
- The size of the Array to create.
Returns
Array.CreateInstance(Type, Int32)
method returns A new one-dimensional Array of the specified Type with the specified length,
using zero-based indexing.
Example
The following code example shows how to create and initialize a one-dimensional Array.
/* ww w . ja va 2s . co m*/
using System;
public class SamplesArray {
public static void Main() {
Array my1DArray=Array.CreateInstance( typeof(Int32), 5 );
for ( int i = my1DArray.GetLowerBound(0); i <= my1DArray.GetUpperBound(0); i++ ){
my1DArray.SetValue( i+1, i );
}
}
}
The code above generates the following result.