Create Array from specified Type and length, with zero-based indexing in CSharp
Description
The following code shows how to create Array from specified Type and length, with zero-based indexing.
Example
using System;/*from w ww.ja v a 2 s. co m*/
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 );
}
foreach(int i in my1DArray){
Console.WriteLine(i);
}
}
}
The code above generates the following result.