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];
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.