Create a multidimensional array

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet creates a multidimensional Array of the specified Type, dimension lengths, and lower bounds.

using System;
 
public class MultidimensionalArray
{
   public static void Main()
   {
      int[] lowerBounds = {1, 2, 4};
      int[] lengths     = {4, 2, 1};
      Console.WriteLine
         ("One dimensional array lower bound = {0}", 
         new string[10].GetLowerBound (0));      
      Array array = Array.CreateInstance 
         (typeof (int), lengths, lowerBounds);
      Console.WriteLine
         ("Bounds dimension {0} = [{1},{2}]", 
         0, array.GetLowerBound (0), array.GetUpperBound (0)); 
      Console.WriteLine
         ("Bounds dimension {0} = [{1},{2}]", 
         1, array.GetLowerBound (1), array.GetUpperBound (1)); 
      Console.WriteLine
         ("Bounds dimension {0} = [{1},{2}]", 
         2, array.GetLowerBound (2), array.GetUpperBound (2));
   } 
}


 Multi-dimensional Array example (program output)
One dimensional array lower bound = 0
Bounds dimension 0 = [1,4]
Bounds dimension 1 = [2,3]
Bounds dimension 2 = [4,4]

Today's Deals: Electronics

Personal tools