Multi-Dimensional
Lesson 11 of 14 in Coddy's Strings and Arrays in C# course.
A multi-dimensional array is an array of arrays.
To create a two-dimensional array, add each array within its own set of curly braces:
int[,] myNumbers = {{1, 2, 3, 4}, {5, 6, 7}};An example of element access:
Console.WriteLine(myNumbers[1, 2]); // Outputs 7And modifying elements:
myNumbers[1, 2] = 5;
Console.WriteLine(myNumbers[1, 2]); // Outputs 5Note: The single comma
[,]specifies that the array is two-dimensional. A three-dimensional array would have two commas:int[,,], and so on…
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Try it yourself
This lesson doesn't include a code challenge.