Thank you all.
What gets me is that I followed the example on MSDN
http://msdn2.microsoft.com/en-us/library/2s05feca(VS.80).aspx
Why isn't this documented
> Further to Arne's reply, you could also use array-initializer syntax
> (below), but it seems unlikely that you would generally know these
[quoted text clipped - 7 lines]
>
> Marc
Marc Gravell - 25 Nov 2007 10:02 GMT
> Why isn't this documented
I'm assuming you mean "that you can't use regular code outside of a
method" - this is documented in many, many places. In particular the
language spec.
Re the sample - it doesn't say that "jaggedArray" is a field. The code
as presented would be perfectly valid as contents of a method, with
"jaggedArray" as a local variable.
Marc
Alun Harford - 25 Nov 2007 16:06 GMT
> Thank you all.
>
> What gets me is that I followed the example on MSDN
> http://msdn2.microsoft.com/en-us/library/2s05feca(VS.80).aspx
>
> Why isn't this documented
It is.
In the language specification. Section 17 defines what a class can contain.
Informally, a class contains a class-body, which contains 0...n
class-member-declarations, which can be any of:
constant-declaration
field-declaration
method-declaration
property-declaration
event-declaration
indexer-declaration
operator-declaration
constructor-declaration
finalizer-declaration
static-constructor-declaration
type-declaration
string [][] MyString = new string [3][];
This is a field-declaration. It happens to contain a variable-initializer.
MyString[0] = new string[5];
This is just an assignment, which is not valid here.
Alun Harford