Skip to content

Commit 9a120c2

Browse files
authored
Remove misleading sample (#44966)
Fixes #29824 This sample really doesn't involve a discard. It's trying to name two different variables `_`.
1 parent fd0269f commit 9a120c2

File tree

2 files changed

+1
-19
lines changed

2 files changed

+1
-19
lines changed

docs/csharp/fundamentals/functional/discards.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Discards - unassigned discardable variables
33
description: Describes C#'s support for discards, which are unassigned, discardable variables, and the ways in which discards can be used.
4-
ms.date: 11/14/2023
4+
ms.date: 02/19/2025
55
f1_keywords:
66
- "discard_CSharpKeyword"
77
---
@@ -74,8 +74,6 @@ Without assigning the task to a discard, the following code generates a compiler
7474
:::code language="csharp" source="snippets/discards/standalone-discard2.cs" ID="VariableIdentifier" :::
7575
- A compiler error for violating type safety. For example:
7676
:::code language="csharp" source="snippets/discards/standalone-discard2.cs" ID="VariableTypeInference" :::
77-
- Compiler error CS0136, "A local or parameter named '\_' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter." For example:
78-
:::code language="csharp" source="snippets/discards/standalone-discard2.cs" ID="CannotRedeclare" :::
7977

8078
## See also
8179

docs/csharp/fundamentals/functional/snippets/discards/standalone-discard2.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,5 @@ private static bool RoundTrips(int _)
3232
// error CS0029: Cannot implicitly convert type 'bool' to 'int'
3333
// </VariableTypeInference>
3434
35-
// <CannotRedeclare>
36-
public void DoSomething(int _)
37-
{
38-
var _ = GetValue(); // Error: cannot declare local _ when one is already in scope
39-
}
40-
// The example displays the following compiler error:
41-
// error CS0136:
42-
// A local or parameter named '_' cannot be declared in this scope
43-
// because that name is used in an enclosing local scope
44-
// to define a local or parameter
45-
// </CannotRedeclare>
4635
*/
47-
48-
private int GetValue()
49-
{
50-
return 3;
51-
}
5236
}

0 commit comments

Comments
 (0)