Array in c#


We can store multiple variables of the same type in an array data structure, so An array stores a fixed-size sequential collection of elements of the same type. A fixed-length array can store a predefined number of items. A dynamic array does not have a predefined size. The size of a dynamic array increases as you add new items to the array. You can declare an array of fixed length or dynamic.

Example of Array in c#:-

int[] array = new int[4];
array[0] = 10;
array[1] = 20;
array[2] = 30;
array[3] = 40;

More Examples of the array in c#

int[] intArray;  // can store int values
bool[] boolArray; // can store boolean values
string[] stringArray; // can store string values

Array Types in c#
1.      Single-dimensional arrays
2.      Multidimensional arrays or rectangular arrays
3.      Jagged arrays
4.      Mixed arrays.

Single Dimension Arrays
int[] intArray;
intArray = new int[3];

Multi-Dimensional Arrays
Array with more than one dimension is called multi- Dimensional. The form of a multi-dimensional array is a matrix.

Example:-
int[,] numbers = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };

Jagged Arrays

Jagged arrays are arrays of arrays.
int[][] intJaggedArray = new int[3][];
intJaggedArray[0] = new int[2]; 
intJaggedArray[1] = new int[4]; 
intJaggedArray[2] = new int[6]; 

Mixed Arrays
Mixed arrays are a combination of multi-dimension arrays and jagged arrays.