![]() |
|
Arrays in C#, Free online C# Programming Tutorial... |
| Lessons | C# Arrays |
|
int[] i = new int[2]; i[0] = 1; i[1] = 2; By default all arrays start with their lower bound as 0. However, using the .NET framework's System.Array class it is possible to create and manipulate arrays with an alternative initial lower bound. Like Java, C# supports two types of multidimensional arrays: 1. Rectangular and 2. Jagged. Rectangular Arrays: A rectangular array is a single array with more than one dimension, with the dimensions' sizes fixed in the array's declaration. Here is an example: int[ , ] squareArray = new int[2 , 3]; As with single-dimensional arrays, rectangular arrays can be filled at the time they are declared. Jagged Arrays Jagged arrays are multidimensional arrays with irregular dimensions. This flexibility derives from the fact that multidimensional arrays are implemented as arrays of arrays. int[][] jag = new int[2][]; jag[0] = new int [4]; jag[1] = new int [6]; Each one of jag[0] and jag[1] holds a reference to a single-dimensional int array.
Next >>> Lesson No. 14: C# Objects and Classes
|