Skip to content

Commit 0cf3446

Browse files
committed
Edit pass
Do a final edit pass.
1 parent 12edaf3 commit 0cf3446

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ f1_keywords:
77
helpviewer_keywords:
88
- "using directive [C#]"
99
---
10-
# using directive
10+
# The `using` directive
1111

1212
The `using` directive allows you to use types defined in a namespace without specifying the fully qualified namespace of that type. In its basic form, the `using` directive imports all the types from a single namespace, as shown in the following example:
1313

@@ -35,7 +35,7 @@ You can use the `global` modifier on a *using alias directive*.
3535
3636
The scope of a `using` directive without the `global` modifier is the file in which it appears.
3737

38-
The `global using` directive must appear before all namespace and type declarations. All global using directives must appear in a source file before any non-global `using` directives.
38+
The `global using` directive must appear before all namespace and type declarations. All global using directives must appear in a source file before any nonglobal `using` directives.
3939

4040
Other `using` directives can appear:
4141

@@ -46,36 +46,36 @@ Otherwise, a compiler error is generated.
4646

4747
Create a `using` directive to use the types in a namespace without having to specify the namespace. A `using` directive doesn't give you access to any namespaces that are nested in the namespace you specify. Namespaces come in two categories: user-defined and system-defined. User-defined namespaces are namespaces defined in your code. For a list of the system-defined namespaces, see [.NET API Browser](../../../../api/index.md).
4848

49-
## global modifier
49+
## The `global` modifier
5050

5151
Adding the `global` modifier to a `using` directive means that using is applied to all files in the compilation (typically a project). The `global using` directive was added in C# 10. Its syntax is:
5252

5353
```csharp
5454
global using <fully-qualified-namespace>;
5555
```
5656

57-
where *fully-qualified-namespace* is the fully qualified name of the namespace whose types can be referenced without specifying the namespace.
57+
Where *fully-qualified-namespace* is the fully qualified name of the namespace whose types can be referenced without specifying the namespace.
5858

5959
A *global using* directive can appear at the beginning of any source code file. All `global using` directives in a single file must appear before:
6060

6161
- All `using` directives without the `global` modifier.
6262
- All namespace and type declarations in the file.
6363

64-
You may add `global using` directives to any source file. Typically, you'll want to keep them in a single location. The order of `global using` directives doesn't matter, either in a single file, or between files.
64+
You can add `global using` directives to any source file. Typically, you want to keep them in a single location. The order of `global using` directives doesn't matter, either in a single file, or between files.
6565

66-
The `global` modifier may be combined with the `static` modifier. The `global` modifier may be applied to a *using alias directive*. In both cases, the directive's scope is all files in the current compilation. The following example enables using all the methods declared in the <xref:System.Math?displayProperty=fullName> in all files in your project:
66+
The `global` modifier can be combined with the `static` modifier. The `global` modifier can be applied to a *using alias directive*. In both cases, the directive's scope is all files in the current compilation. The following example enables using all the methods declared in the <xref:System.Math?displayProperty=fullName> in all files in your project:
6767

6868
```csharp
6969
global using static System.Math;
7070
```
7171

7272
You can also globally include a namespace by adding a `<Using>` item to your project file, for example, `<Using Include="My.Awesome.Namespace" />`. For more information, see [`<Using>` item](../../../core/project-sdk/msbuild-props.md#using).
7373

74-
Analyzers issue diagnostics if you've duplicated `global` using directives in different locations. These same analyzers also inform you if you add a `using` directive for a namespace or type that is already referenced by a `global` using directive. You might find it easier to manage your `global` usings by keeping them together in one file in the project.
74+
Analyzers issue diagnostics if you duplicate `global` using directives in different locations. These same analyzers also inform you if you add a `using` directive for a namespace or type that a `global` using directive already references. You might find it easier to manage your `global` usings by keeping them together in one file in the project.
7575

7676
[!INCLUDE [csharp10-templates](../../../../includes/csharp10-templates.md)]
7777

78-
## static modifier
78+
## The `static` modifier
7979

8080
The `using static` directive names a type whose static members and nested types you can access without specifying a type name. Its syntax is:
8181

@@ -109,19 +109,19 @@ By eliminating the need to explicitly reference the <xref:System.Math> class eac
109109

110110
:::code language="csharp" source="./snippets/using-static2.cs":::
111111

112-
`using static` imports only accessible static members and nested types declared in the specified type. Inherited members aren't imported. You can import from any named type with a `using static` directive, including Visual Basic modules. If F# top-level functions appear in metadata as static members of a named type whose name is a valid C# identifier, then the F# functions can be imported.
112+
`using static` imports only accessible static members and nested types declared in the specified type. Inherited members aren't imported. You can import from any named type with a `using static` directive, including Visual Basic modules. If F# top-level functions appear in metadata as static members of a named type whose name is a valid C# identifier, then the F# functions can be imported.
113113

114-
`using static` makes extension methods declared in the specified type available for extension method lookup. However, the names of the extension methods aren't imported into scope for unqualified reference in code.
114+
`using static` makes extension methods declared in the specified type available for extension method lookup. However, the names of the extension methods aren't imported into scope for unqualified reference in code.
115115

116-
Methods with the same name imported from different types by different `using static` directives in the same compilation unit or namespace form a method group. Overload resolution within these method groups follows normal C# rules.
116+
Methods with the same name imported from different types by different `using static` directives in the same compilation unit or namespace form a method group. Overload resolution within these method groups follows normal C# rules.
117117

118118
The following example uses the `using static` directive to make the static members of the <xref:System.Console>, <xref:System.Math>, and <xref:System.String> classes available without having to specify their type name.
119119

120120
:::code language="csharp" source="./snippets/using-static3.cs" id="Snippet1":::
121121

122-
In the example, the `using static` directive could also have been applied to the <xref:System.Double> type. Adding that directive would make it possible to call the <xref:System.Double.TryParse(System.String,System.Double@)> method without specifying a type name. However, using `TryParse` without a type name creates less readable code, since it becomes necessary to check the `using static` directives to determine which numeric type's `TryParse` method is called.
122+
In the example, the `using static` directive could also be applied to the <xref:System.Double> type. Adding that directive would make it possible to call the <xref:System.Double.TryParse(System.String,System.Double@)> method without specifying a type name. However, using `TryParse` without a type name creates less readable code, since it becomes necessary to check the `using static` directives to determine which numeric type's `TryParse` method is called.
123123

124-
`using static` also applies to `enum` types. By adding `using static` with the enum, the type is no longer required to use the enum members.
124+
`using static` also applies to `enum` types. By adding `using static` with the enum, the type is no longer required to use the enum members.
125125

126126
```csharp
127127
using static Color;
@@ -142,7 +142,7 @@ class Program
142142
}
143143
```
144144

145-
## using alias
145+
## The `using` alias
146146

147147
Create a `using` alias directive to make it easier to qualify an identifier to a namespace or type. In any `using` directive, the fully qualified namespace or type must be used regardless of the `using` directives that come before it. No `using` alias can be used in the declaration of a `using` directive. For example, the following example generates a compiler error:
148148

@@ -165,9 +165,9 @@ Beginning with C# 12, you can create aliases for types that were previously rest
165165

166166
## Qualified alias member
167167

168-
The namespace alias qualifier, `::` provides explicit access to the global namespace or other using aliases that are potentially hidden by other entities.
168+
The namespace alias qualifier, `::` provides explicit access to the global namespace or other using aliases potentially hidden by other entities.
169169

170-
The `global::` ensures that the namespace lookup for the namespace to the right of the `::` token is relative to the global namespace. Otherwise, the token must resolve to a using alias, and the token to the right must resolve to a type in that aliased namespace. The following example shows both forms:
170+
The `global::` ensures that the namespace lookup for the namespace following the `::` token is relative to the global namespace. Otherwise, the token must resolve to a using alias, and the token following the `::` must resolve to a type in that aliased namespace. The following example shows both forms:
171171

172172
:::code language="csharp" source="./snippets/UsingAliasQualifier.cs" id="UsingAliasQualifier":::
173173

0 commit comments

Comments
 (0)