13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONint[,] b = new int[5, 2];and then initializes the array instance with the following values:b[0, 0] = 0; b[0, 1] = 1;b[1, 0] = 2; b[1, 1] = 3;b[2, 0] = 4; b[2, 1] = 5;b[3, 0] = 6; b[3, 1] = 7;b[4, 0] = 8; b[4, 1] = 9;end example]When an array creation expression includes both explicit dimension lengths and an array initializer, thelengths must be constant expressions and the number of elements at each nesting level must match thecorresponding dimension length. [Example: Here are some examples:int i = 3;int[] x = new int[3] {0, 1, 2}; // OKint[] y = new int[i] {0, 1, 2}; // Error, i not a constantint[] z = new int[3] {0, 1, 2, 3}; // Error, length/initializer mismatchHere, the initializer for y results in a compile-time error because the dimension length expression is not aconstant, and the initializer for z results in a compile-time error because the length and the number ofelements in the initializer do not agree. end example]278

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!