Array provides the following methods and properties for querying length and rank:
public int GetLength (int dimension);
public long GetLongLength (int dimension);
public int Length { get; }
public long LongLength { get; }
public int GetLowerBound (int dimension);
public int GetUpperBound (int dimension);
public int Rank { get; } // Returns number of dimensions in 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);
Console.WriteLine(a.Length);
}
}
The output:
2
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. |