This article describes the basic usage of C# two-dimensional arrays. Share it for your reference, as follows:
//Define arraystring[,] classes = new string[5, 2]; //Correct C# How to use two-dimensional arraysclasses[i, 0] = "";//Incorrect usage methodclasses[i][0]="";
It is said that this form of C# two-dimensional array is called a sawtooth array.
An example for reference:
// Declare a jagged array with two elementsint[][] myArray = new int[2][]; // The first element is an array containing five elements// Initialize myArray[0]myArray[0] = new int[5] {1,3,5,7,9}; // The second element is an array with 4 elements// Initialize myArray[1]myArray[1] = new int[4] {0, 2, 4, 6}; // Print out all elements in the array one by onefor (int i=0; i < ; i++) { ("The({0})Arrays: ", i); // Print elements in a one-dimensional array for (int j=0; j < myArray[i].Length; j++) { ("{0} ", myArray[i][j]); } (); }
I hope this article will be helpful to everyone's C# programming.