Windows Phone Developers

Friday, December 5, 2008

Automatic initialization of arrays in .NET (C#)

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:

Auto Initialization of Arrays in C#

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment