Why does C# allow code blocks without a preceding statement (e.g. if, else, for, while)?
void Main()
{
I consider {} as a statement that can contain several statements.
Consider an if statement that exists out of a boolean expression followed by one statement. This would work:
if (true) Console.Write("FooBar");
This would work as well:
if (true)
{
Console.Write("Foo");
Console.Write("Bar");
}
If I'm not mistaken this is called a block statement.
Since {} can contain other statements it can also contain other {}.
The scope of a variable is defined by it's parent {} (block statement).
The point that I'm trying to make is that {} is just a statement, so it doesn't require an if or whatever...