Array sizes and dimensions. : Array Length « Data Structure « C# / CSharp Tutorial






using System;

class MainClass {

    public static void PrintArray(int[] arr) {
        for (int i = 0; i < arr.Length; ++i)
            Console.WriteLine("OneDArray Row {0} = {1}", i, arr[i]);
    }

    public static void PrintArrayRank(int[,] arr) {
        Console.WriteLine("PrintArrayRank: {0} dimensions", arr.Rank);
    }


    public static void Main() {
        int[] x = new int[10];
        for (int i = 0; i < 10; ++i)
            x[i] = i;
        PrintArray(x);

        int[,] y = new int[10, 20];
        for (int k = 0; k < 10; ++k)
            for (int i = 0; i < 20; ++i)
                y[k, i] = i * k;
        PrintArrayRank(y);
    }
}








11.4.Array Length
11.4.1.Use the Length array property
11.4.2.Use the Length array property on a 3-D array
11.4.3.Demonstrate Length with jagged arrays.
11.4.4.Use the GetLength() method to get number of elements in each dimension of the two dimensional array
11.4.5.Array sizes and dimensions.
11.4.6.Using Length - 1 in the Array Index
11.4.7.Defining the Array Size at Runtime