string[,]
- Multidimensional Arrary (Rectangular array)
Multidimensional can have more than one dimension. The following example shows how to create a two-dimensional array of two rows and two columns.
Declaration :
string[,] contacts;
Instantiation:
string[,] contacts = new string[2,2];
Initialization :
string[,] contacts = new string[2, 2] { {"John Doe","johndoe@example.com"}, {"Jane Doe","janedoe@example.com"} };
string[ ][ ]
- Jagged Array (Array-of-arrays)
A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array-of-arrays."
A jagged array can store efficiently many rows of varying lengths. Any type of data, reference or value, can be used. Indexing jagged arrays is fast. Allocating them is somewhat slow.
Jagged arrays are faster than multidimensional arrays
Declaration :
string[][] contacts;
Instantiation:
string[][] contacts = new string[2][];
for (int i = 0; i < contacts.Length; i++)
{
contacts[i] = new string[3];
}
Initialization :
string[][] contacts = new string[2][] { new string[] {"john@example.com","johndoe@example.com"}, new string[] {"janedoe@example.com","jane@example.com","doe@example.com"} };