Introduction:
Arrays are data type of fixed size, it is a data structure composed of columns and rows, it is a two dimensional data structure having a tabular kind structure with a column index and row index, here we would how we can use arrays in c#.
We are considering an array named as X, the size of array X is 6 from index 0 to 5, the first index of an array starts with index 0 and so on.
Array X[6]
4 |
5 |
1 |
15 |
34 |
11 |
X[0] X[1] X[2] X[3] X[4] X[5]
arrays can only stored data of fixed type, we can have arrays of string, arrays of Int, and so on, so we declare arrays in c# as
datatype[] arrayname;
first we will have some data type followed by [] brackets and then the name of the array, where as [] determines the rank or the size of the array.
we can declare an array of int as
int[] myarray=new int[10];
so it is an array being named as myarray of size 10, and the arrays indexing starts from myarray[0] to myarray[9].
Now, here we will consider an example to see how can arrays be used in c#, so first we will create a new project in Visual Studio as a console based application,