Reading a book (VS 2010), it says that commands (statements) in .NET Csharp cannot exist outside of method.
I am wondering – field declaration etc, these are commands, are they not? And they exist at class level. Can somebody elaborate at this a bit?
Reading a book (VS 2010), it says that commands (statements) in .NET Csharp cannot
Share
There’s no such concept as a “command” in C#.
And a static / instance variable declaration isn’t categorized as a statement within C# – it’s a field-declaration (which is a type of class-member-declaration) as per the C# spec. See section 10.5 of the C# 4 spec for example.
Now the statements which declare local variables are statements, as defined by declaration-statement in the spec (section 8.5). They’re only used for locals though. See section B.2.5 for a complete list of statement productions within C# 4.
Basically, the C# spec defines the terminology involved – so while you might think informally of “commands” and the like, in a matter of correctness the C# spec is the source of authority. (Except for where it doesn’t say what the language designers meant to say, of course. That’s pretty rare.)