Create three-dimensional Array of the specified Type and dimension, with zero-based indexing in CSharp

Description

The following code shows how to create three-dimensional Array of the specified Type and dimension, with zero-based indexing.

Example


//from   w w  w .jav a2s .c o m
using System;
public class SamplesArray  {

   public static void Main()  {

      Array my3DArray=Array.CreateInstance( typeof(Object), 2, 3, 4 );
      for ( int i = my3DArray.GetLowerBound(0); i <= my3DArray.GetUpperBound(0); i++ )
         for ( int j = my3DArray.GetLowerBound(1); j <= my3DArray.GetUpperBound(1); j++ )
            for ( int k = my3DArray.GetLowerBound(2); k <= my3DArray.GetUpperBound(2); k++ ){
               my3DArray.SetValue( "abc", i, j, k );
               Console.WriteLine("abc");
            }

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var