Constructs a zero-based, one-dimensional array with the specified number of elements of the specified type.
A zero-based, one-dimensional Array object containing length elements of type elementType.
Type Reason ArgumentNullException elementType is null. ArgumentException elementType is not a valid Type. ArgumentOutOfRangeException length < 0.
Reference-type elements will be set to null. Value-type elements will be set to zero, except for bool elements, which will be set to false.
Note: Unlike most classes, Array provides the Array.CreateInstance(Type, int) method, instead of public constructors, to allow for late bound access.
The following example shows how to create and initialize a one-dimensional Array.
C# Example
using System; public class ArrayCreateInstanceExample { public static void Main() { Array intAry = Array.CreateInstance(typeof(int),5); for (int i=intAry.GetLowerBound(0);i<=intAry.GetUpperBound(0);i++) intAry.SetValue(i*3,i); Console.Write("The values of the array are:"); foreach (int i in intAry) Console.Write("{0} ",i); } }The output is
The values of the array are: 0 3 6 9 12
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0