Use Array.CreateInstance to create array instance : Array CreateInstance « Data Structure « C# / CSharp Tutorial






using System;

public class MainClass
{
  public static void Main() {
    // Create and initialize a new Array instance.
    Array strArr = Array.CreateInstance( typeof(String), 3 );
    strArr.SetValue( "M", 0 );
    strArr.SetValue( "C", 1 );
    strArr.SetValue( "T", 2 );
        
    // Display the values of the Array.
    Console.WriteLine( "Initial Array values:" );
    for ( int i = strArr.GetLowerBound(0); i <= strArr.GetUpperBound(0); i++ )
      Console.WriteLine( strArr.GetValue( i ) );
  }
}
Initial Array values:
M
C
T








11.13.Array CreateInstance
11.13.1.Dynamic array creation
11.13.2.Use Array.CreateInstance to create array instance
11.13.3.Create Array With Bounds