O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Initializing Arrays

The array elements of an array can be initialized, with values of your choice, at the time the array is being created. To accomplish this, you first need to write the declaration of the array variable as usual. However, instead of creating the array object using the new keyword, as in the following

new int [6];

you can specify the list of initialization values explicitly by enclosing them in braces, and assigning this list to the array variable with the assignment operator. The following line follows this procedure:

The array object is automatically created with just enough array elements (six, in this example) to hold the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required