From b92b49efb6fc4462010a2e321aafa41ac81a8d66 Mon Sep 17 00:00:00 2001 From: Marcin Grygierczyk Date: Sun, 18 Nov 2018 21:00:14 +0100 Subject: [PATCH] Add description of multidimensional arrays (#22210) --- guide/english/csharp/array/index.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/guide/english/csharp/array/index.md b/guide/english/csharp/array/index.md index df9e8bdc36..aab144e3f4 100644 --- a/guide/english/csharp/array/index.md +++ b/guide/english/csharp/array/index.md @@ -116,6 +116,31 @@ Console.Write(array[1][2]); // Displays 3 (third element of second subarray) Console.Write(array[1][0]); // Displays 1 (first element of second subarray) ``` +## Multidimensional array +Arrays can have more than one dimension (every element will be represented by more than one index). Example of declaration and initialization of two dimensional array: + +```csharp +string[,] weekDays = new string[2, 3]; +``` + +Having two dimensional array we need to use two indexes to represent the position of element: + +```csharp +weekDays[0,0] = "monday"; +weekDays[0,1] = "montag"; +weekDays[0,2] = "lundi"; +weekDays[1,0] = "tuesday"; +weekDays[1,1] = "dienstag"; +weekDays[1,2] = "mardi"; +``` + +To check number of dimensions we can use Rank property: + +```csharp +int[,,,] array = new int[6, 4, 2, 8]; +Console.WriteLine(array.Rank); // 4 +``` + ## Advantages * Can be easily accessed in a random manner