www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons C# Arrays Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Arrays in C# are more similar to Java than to C++. We can create an array in C# very similarly as we do the same in Java by using the new operator. Once created, the array can be used as usual, as shown below:

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







Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.