Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/core/docker/snippets/App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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}");

await Task.Delay(TimeSpan.FromMilliseconds(1_000));
// Wait for one second between iterations
await Task.Delay(TimeSpan.FromSeconds(1));
}
56 changes: 39 additions & 17 deletions docs/csharp/misc/cs0409.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
---
description: "Compiler Error CS0409"
title: "Compiler Error CS0409"
ms.date: 07/20/2015
f1_keywords:
ms.date: 09/15/2021
f1_keywords:
- "CS0409"
helpviewer_keywords:
helpviewer_keywords:
- "CS0409"
ms.assetid: 23d86c13-7978-41b7-a087-ffcea52476fa
---
# Compiler Error CS0409

A constraint clause has already been specified for type parameter 'type parameter'. All of the constraints for a type parameter must be specified in a single where clause.

Multiple constraint clauses (where clauses) were found for a single type parameter. Remove the extraneous where clause, or correct the where clauses so that a unique type parameter in each clause.

```csharp
// CS0409.cs
interface I
{
}

class C<T1, T2> where T1 : I where T1 : I // CS0409 – T1 used twice
{
}
A constraint clause has already been specified for type parameter 'type parameter'. All of the constraints for a type parameter must be specified in a single where clause.

Multiple constraint clauses (`where` clauses) were specified for the same type parameter. To fix this error, remove the duplicate `where` clause, or change the constraint clauses so each one applies to a unique type parameter.

## Example

The following example generates CS0409:

```csharp
class Example<T>
where T : class
where T : new()
{
}
```

To fix this error, combine the constraints into a single clause:

```csharp
class Example<T>
where T : class, new()
{
}
```

The following sample also generates CS0409:

```csharp
// CS0409.cs
interface I
{
}

class C<T1, T2> where T1 : I where T1 : I // CS0409 - T1 used twice
{
}
```
Loading