What is an array in C# programming?

 Posted by Goud.Kv on 9/3/2014 | Category: C# Interview questions | Views: 378 | Points: 40

Array is a set of variables which are called as its elements. It is a fixed set of variables.
Array elements store in the contiguous block of memory due to their high efficient access.

We can create arrays with char, string etc. For example,
char[] vowels = new vowels[5]; // Array with 5 elements
This is the declaration of array for char's.
The length of the above array is 5.
Now we can create elements like below,
vowels[0] = 'A';

vowels[1] = 'E';
vowels[2] = 'I';
vowels[3] = 'O';
vowels[4] = 'U';
Array index must start with 0.

Other ways of declaring an array are,
char[] vowels = new vowels[5] { 'A', 'E', 'I', 'O', 'U' };
char[] vowels = { 'A', 'E', 'I', 'O', 'U' };

Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response