You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using *file-scoped namespaces*, the placement of `using` statements affects their scope within the file. File-scoped namespaces lower to the equivalent traditional namespace declaration that ends with a closing bracket at the end of the file. This behavior determines where `using` directives are applied as follows:
26
+
27
+
- If the `using` statements are placed before the file-scoped namespace declaration, they are treated as being outside of the namespace and are interpreted as fully-qualified namespaces.
28
+
- If the `using` statements are placed after the file-scoped namespace declaration, they are scoped within the namespace itself.
29
+
30
+
For example:
31
+
32
+
```csharp
33
+
// This using is outside the namespace scope, so it applies globally
In the above example, `System` is globally accessible, while `System.Text` applies only within `SampleNamespace`.
48
+
23
49
The preceding example doesn't include a nested namespace. File scoped namespaces can't include additional namespace declarations. You cannot declare a nested namespace or a second file-scoped namespace:
0 commit comments