Mono Class Library: System.Array Overview | MembersSystem.Array.CreateInstance Method |
Constructs a zero-based, one-dimensional array with the specified number of elements of the specified type. [Edit]
|
A zero-based, one-dimensional Array object containing length elements of type elementType. [Edit]
Type Reason ArgumentNullException elementType is null. [Edit] ArgumentException elementType is not a valid Type. [Edit] ArgumentOutOfRangeException length < 0. [Edit]
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.[Edit]
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