Skip to content
Closed
18 changes: 13 additions & 5 deletions docs/core/docker/snippets/App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
var counter = 0;
var max = args.Length is not 0 ? Convert.ToInt32(args[0]) : -1;

while (max is -1 || counter < max)
// If a number is passed as a command-line argument,
// it will be used as the maximum counter value.
var max = args.Length > 0 && int.TryParse(args[0], out var parsedMax)
? parsedMax
: -1;

// Run indefinitely if no max value is provided
while (max == -1 || counter < max)
{
Console.WriteLine($"Counter: {++counter}");
counter++;
Console.WriteLine($"Counter: {counter}");

await Task.Delay(TimeSpan.FromMilliseconds(1_000));
}
// Wait for one second between iterations
await Task.Delay(TimeSpan.FromSeconds(1));
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ f1_keywords:
- "CS8914"
- "CS8915"
- "CS8933"
- "CS8954"
- "CS8955"
- "CS8956"
- "CS9130"
- "CS9131"
- "CS9132"
Expand All @@ -44,6 +47,9 @@ helpviewer_keywords:
- "CS8914"
- "CS8915"
- "CS8933"
- "CS8954"
- "CS8955"
- "CS8956"
- "CS9130"
- "CS9131"
- "CS9132"
Expand Down Expand Up @@ -71,6 +77,9 @@ That's be design. The text closely matches the text of the compiler error / warn
- [**CS8085**](#restrictions-on-using-aliases): *Error: A 'using static' directive cannot be used to declare an alias.*
- [**CS8914**](#global-using-directive): *Error: A global using directive cannot be used in a namespace declaration.*
- [**CS8915**](#global-using-directive): *Error: A global using directive must precede all non-global using directives.*
- [**CS8954**](#global-using-directive): *Error: A global using directive must precede all non-global using directives.*
- [**CS8955**](#global-using-directive): *Error: A file-local type cannot be used in a global using directive.*
- [**CS8956**](#using-directive-placement): *Error: A using directive must precede all other elements defined in the namespace except extern alias declarations.*
- [**CS9130**](#restrictions-on-using-aliases): *Error: Using alias cannot be a `ref` type.*
- [**CS9131**](#restrictions-on-using-aliases): *Error: Only a using alias can be `unsafe`.*
- [**CS9132**](#restrictions-on-using-aliases): *Error: Using alias cannot be a nullable reference type.*
Expand Down Expand Up @@ -107,6 +116,10 @@ The compiler produces warning **CS8933**, **CS0105** or diagnostic **CS8019** fo

Incorrectly combining a `using` directive with the `static`, `global`, or `unsafe` modifiers on a `using` directive are covered later in this article.

The compiler also produces **CS8956** when a using directive doesn't appear before other elements defined in a namespace (except extern alias declarations).



## Using static directive

The `using static` directive imports one type's members into the current namespace. The following example imports the methods from `System.Console`, such as `WriteLine` into the current namespace:
Expand Down Expand Up @@ -141,6 +154,15 @@ Any `global using` directives must precede any non-global `using` directives in

Furthermore, a `static global using` directive can't reference a [file-local](../keywords/file.md) type.

Violating these rules can also produce the following errors:

### CS8954
A global using directive must precede all non-global using directives.

### CS8955
A file-local type cannot be used in a global using directive.


## Alias qualifier

The alias qualifier, [`::`](../operators/namespace-alias-qualifier.md), precedes a namespace alias, or follows the `global` alias. If you use `::` where `.` should be used to separate elements of a fully qualified name, the compiler emits one of **CS0431**, **CS0432**, **CS0687**, **CS7000*, or **CS8083**.
Expand Down
Loading