Mega Code Archive
0347 Array Class
The Array class is the implicit base class for all single and multidimensional arrays.
Construction and Indexing
The static GetValue and SetValue methods access elements in a dynamically created array.
using System;
using System.Collections;
class Sample
{
public static void Main()
{
// Create a string array 2 elements in length:
Array a = Array.CreateInstance(typeof(string), 2);
a.SetValue("hi", 0);
a.SetValue("there", 1);
string s = (string)a.GetValue(0);
// We can cast to a C# array as follows:
string[] cSharpArray = (string[])a;
string s2 = cSharpArray[0];
}
}