Skip to content

Commit 959e1f5

Browse files
Update using-directive.md (#47993)
using static doesn't require a fully qualified type if it is in the scope of a namespace. see: https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/namespaces.md#1354-using-static-directives here the grammar is: > using_static_directive > : 'using' 'static' type_name ';' > ;
1 parent ad69965 commit 959e1f5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

docs/csharp/language-reference/keywords/using-directive.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ Analyzers issue diagnostics if you duplicate `global` using directives in differ
8282
The `using static` directive names a type whose static members and nested types you can access without specifying a type name. Its syntax is:
8383

8484
```csharp
85+
// not within a namespace
8586
using static <fully-qualified-type-name>;
8687
```
8788

8889
The `<fully-qualified-type-name>` is the name of the type whose static members and nested types can be referenced without specifying a type name. If you don't provide a fully qualified type name (the full namespace name along with the type name), C# generates compiler error [CS0246](../compiler-messages/assembly-references.md): "The type or namespace name 'type/namespace' couldn't be found (are you missing a using directive or an assembly reference?)".
8990

91+
If the `using static` directive is applied within the context of a namespace (either file-scoped or nested in a `namespace` block, it is not necessary to fully qualify the type.
92+
9093
The `using static` directive applies to any type that has static members (or nested types), even if it also has instance members. However, instance members can only be invoked through the type instance.
9194

9295
You can access static members of a type without having to qualify the access with the type name:

0 commit comments

Comments
 (0)