Why is ;; allowed after a local variable declaration, but not after a field declaration?
Solution 1:
;
alone is a statement (empty statement), but only declaration statements are allowed in the body of a class; other kinds of statement can only appear in the body of a method.
Solution 2:
;
itself is an empty statement. And in class scope only the declaration statements are allowed.The class body is defined in C# Specification 5.0, §10.1.6 Class Body
class-body:
{ class-member-declarations }
For example you can't initialize a field in a separate statement:
class Foo
{
int x = 2; // this is allowed
x = 5; // this is not
}
So you can only declare fields and other members but you can't use other statements in a class body.