Check Page Rank of your Web site pages instantly:

The Example Of Dynamic And Fixed Arrays

Arrays can be either fixed length array or dynamic arrays. In a fixed length array, the number of element is defined at the time of declaration. For example, an array declared for storing days of the week will have exactly seven element. Here the number of elements is known and hence can be define at the time of declaration. Therefore, a fixed length array can be used. On the other hand , in a dynamic array, the size of the array is not fixed at  the time of the array declaration and can dynamically increase at runtime or when ever required , for example , an array declared to store the mail addressed of all users who access a particular web side can not have a predefined length. In such a case the length of the array cannot be specified at the time od declaration . Here a dynamic array has to be used. A dynamic array can add more element to the array as and when required . Dynamic array are created using built in class of the .NET Framework.

Example:

Using System;
Class myclass
{
Static void Main (string [] a)
{
    String [] Days = new string [7];
    Days [0] = “sun”;
    Days [1] = “mon”;
    Days [2] = “tue”;
    Days [3] = “wed”;
    Days [4] = “thr”;
    Days [5] = “fri”;
    Days [6] = “sat”;
For (int I =< days.Leangth; i++)
{
Console.writeLine(Days[i]);
}
}
}


A fixed length array variable , days,of data type string, is declared to store the seven days of week. The days from Sunday to Saturday are stored in the index position 0to6 of the array and are displayed on the console using the Console.writeLine() method.

0 comments:

Post a Comment