C#-Array
What is Array?
An array consists of contiguous memory location. The lowest address correspond to first element and highest address correspond to last element.
1. Declaring Arrays:-
syntax:- datatype[] arrayName;
where
- datatype is used to specify the element in an array
- [] specifies the rank of array
- arrayName specifies the name of the array.
2. Initializing an Array:-
Declaring the array does not initialize the array in the memory.When the array variable is initialize,you can assign value to the array.
For Example:-
double[] balance = new double[10];
3. Assigning Values to an Array:-
You can assign values to individual array element,by using the index number.Also by time of declaration.You also create or initialize an array.
For Example:-
int [] marks = new int[5] {99, 98, 92, 97, 95}
4. Accessing Array Element:-
An Element is accessed by indexing the array name.
For Example:-
double salary = balance[9];

Comments
Post a Comment