Multi Dimensional Array In C# With Example

In this article, we will learn about Multi-Dimensional Array in C# with an example. The Multi-Dimensional Array in C# is a type of array that contains more than one rows to store the data on it. It is also known as the Rectangular Array in C#.NET as it has the same length for each row. This can be a two-dimensional array or a three-dimensional array or more (any N dimension).

Types of Array in C#.NET

Arrays are categorized into the following three categories. 
 Now, create a Console Application in Visual Studio and write the below lines of code in it.
  1. using System;  
  2.  using System.Collections;  
  3.  using System.Collections.Generic;  
  4.     namespace ConsoleDemo  
  5.     {  
  6.         class Program  
  7.         {  
  8.             static void Main(string[] args)  
  9.             {  
  10.                 //Multi-Dimensional array Example  
  11.                 /* Array with 4 rows and 2 columns*/  
  12.                 int[,] _MultiDimentionArray = new int[4, 2] { { 3, 7 }, { 2, 9 }, { 0, 4 }, { 3, 1 } };  
  13.                 int i, j;  
  14.                  
  15.                 for (i = 0; i < 5; i++)  
  16.                 {  
  17.                     for (j = 0; j < 2; j++)  
  18.                     {  
  19.                         Console.WriteLine("a[{0},{1}] = {2}", i, j,  _MultiDimentionArray[i, j]);  
  20.                     }  
  21.                 }  
  22.                 Console.ReadKey();  
  23.             }  
  24.         }      
  25.     } 
I hope you understood the concept of Multi-Dimensional Array in C#.
Ebook Download
View all
Learn
View all