C#-Array


What is Array?

Arrays are used to store multiple values in a single variable,instead of declaring seperate variable for each value.Array define the variable type with square brackets[].Instead of declaring individual variables such number0, number1... and number99, you declare one array variable such as numbers and use numbers[0]  numbers[1] And numbers[99] to represent individual variables.

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

Popular posts from this blog

ASP.NET Overview

SQL AND ,OR, NOT Operators

SQL Joins