I saw this weird behaviour and I wonder if there's a reasonable explanation for this:
When I put by ( by accident) an additional/extra semicolon in a function's local variable like:
public void MyMethod () { int a = 1;; Console.WriteLine(a); //dummy }
It does compile but it shows that it's redundant.
But when I did that with fields (also by accident) , I got an error (compilation) :
Question
Is there any reason for this restrictiveness in fields ?
Nb I already know the other restrictiveness thing for not allowing var
with fields. But here it's something different.
;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With