Arrays are set of similar type of values that are stored sequentially.The values of an array can be stored in different ways like,
1.One-dimensional 2.Two-dimentional 3.Jagged array.
Array index starts with '0'.That means first item of an array will be stored at o th position and the position of last item of an array will be 'total number of items-1'.
C# arrays can be declared as fixed length or dynamic. Fixed length of arrays can be stored pre-defined number of items. The size of dynamic arrays increases as we add new items to the array.
One-dimensional array: <type>[] <name> = new <type>[size];
Example:
Declaration: int[] arr;
Initialization: arr= new int[5] ;
Or simply: int[] arr={list of values};
Two-dimensional array: <type>[,] <name> = <type>[rows,cols];
Example:
int[,] arr;
arr = new int[2,3];
Or simply:
int[,] arr = {list of values};
Jagged array:
Jagged arrays are also used to store the data in the form of rows and columns .But here the number of columns for each row varies.
1.One-dimensional 2.Two-dimentional 3.Jagged array.
Array index starts with '0'.That means first item of an array will be stored at o th position and the position of last item of an array will be 'total number of items-1'.
C# arrays can be declared as fixed length or dynamic. Fixed length of arrays can be stored pre-defined number of items. The size of dynamic arrays increases as we add new items to the array.
One-dimensional array: <type>[] <name> = new <type>[size];
Example:
Declaration: int[] arr;
Initialization: arr= new int[5] ;
Or simply: int[] arr={list of values};
Two-dimensional array: <type>[,] <name> = <type>[rows,cols];
Example:
int[,] arr;
arr = new int[2,3];
Or simply:
int[,] arr = {list of values};
Jagged array:
Jagged arrays are also used to store the data in the form of rows and columns .But here the number of columns for each row varies.
No comments:
Post a Comment