When you declare an array of particular type, the new operator automatically initializes the elements of an array to their default value, which, for example, is zero for all numeric types and null for all reference types.
The following example shows the automatic initialization of arrays in C#:
static void ArrayExample()
{
int[] Marks = new int[5];
string[] Students = new string[5];
for (int i=0;i
{
Console.WriteLine("Student Name: {0} - Marks {1}" , Students[i], Marks[i]);
}
}
The output will be:
No comments:
Post a Comment