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.
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace ConsoleDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
-
-
- int[,] _MultiDimentionArray = new int[4, 2] { { 3, 7 }, { 2, 9 }, { 0, 4 }, { 3, 1 } };
- int i, j;
-
- for (i = 0; i < 5; i++)
- {
- for (j = 0; j < 2; j++)
- {
- Console.WriteLine("a[{0},{1}] = {2}", i, j, _MultiDimentionArray[i, j]);
- }
- }
- Console.ReadKey();
- }
- }
- }
I hope you understood the concept of Multi-Dimensional Array in C#.