ARRAY IN C#.NET

Sometimes when we make any program then we have to use number of variables for storing data’s. Some data’s are of same data type and some of different data types. When we want to store values of same data type then we create number of variables of same data type which reduce the performance of application as well as efficiency.To improve the efficiency of applicationwe follow the concept of arrays.An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. Arrays are defined as collection of similar data types of elements means to say collection of elements which have same data type. By using array we can use concept of loops for inserting values as well as traversing those information.

Types of arrays in C#.NET

Each language follows the concept of arrays. Either we are talking about c, c++ or java. Each language has their own syntax as well as type of array. For example c has two types of array single dimension and multi dimension.

Similarly C#.NET has three types of arrays…..

Single Dimension Array

Whenever we want to access the information by using single index then we use the concept of single dimension array. In a single dimension array all the information is stored in a single a row. For inserting/traversing the information of single dimension array we need only one for loop.

Example 1:inserting of array by using for loop

void insertArray() {int[] num = newint[5]; //An array is declared with 5 variables//Length property of num array is used to calculate the size of the array.for (int i = 0; i < num.Length; i++){Console.Write("Enter Any Value-->"); //A message to console device is displayed.num[i] = Convert.ToInt32(Console.ReadLine()); //A value is stored on i th index of num array.}}

Multi Dimension Array

Whenever we want to store the values in rows and columns format then we used concept of multidimensional array. Whenever we create an array which has more than one dimension then such type of array is called multidimensional array.

Jagged Array

Whenever we want to store the information in hierarchal or parent-child relationship format then we used concept of ragged array. Ragged array is defined as array of array. Suppose we want to store the hierarchy of directory in operating system then we use concept of ragged array.