Using directives outside namespace body is common practice, but what are other code which can be done outside namespace body.
>Solution :
The namespace is optional. If it is omitted, types will be assigned to the global namespace. Therefore, every kind of code allowed at the top-level is allowed outside of the namespace.
// No namespace declaration here
public class MyClass()
{
}
You can explicitly specify this namespace like this:
var c = new global::MyClass();
The documentation says:
The compiler adds a default namespace. This unnamed namespace, sometimes referred to as the global namespace, is present in every file. It contains declarations not included in a declared namespace. Any identifier in the global namespace is available for use in a named namespace.
See: Learn / .NET / C# guide / Language reference / Keywords / namespace