diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 69c2b9d4a098d..108f7ed719657 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -638,6 +638,10 @@ "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs7000.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" }, + { + "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8070.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, { "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8124.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/tuple-errors" @@ -1944,6 +1948,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0139.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0140.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0144.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/new-object-creation-errors" @@ -1956,6 +1964,14 @@ "source_path_from_root": "/docs/csharp/misc/cs0153.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0157.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0158.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0159.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" @@ -1964,6 +1980,14 @@ "source_path_from_root": "/docs/csharp/misc/cs0161.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0162.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0164.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/jump-statement-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0171.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors" diff --git a/docs/csharp/language-reference/compiler-messages/cs8070.md b/docs/csharp/language-reference/compiler-messages/cs8070.md deleted file mode 100644 index a73f3b3cf4657..0000000000000 --- a/docs/csharp/language-reference/compiler-messages/cs8070.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -description: "Compiler Error CS8070" -title: "Compiler Error CS8070" -ms.date: 9/05/2025 -f1_keywords: - - "CS8070" -helpviewer_keywords: - - "CS8070" -author: "StuartMosquera" ---- -# Compiler Error CS8070 - -Control cannot fall out of switch from final case label ('label') - -This error occurs when the last `case` or `default` case of a [switch statement](../statements/selection-statements.md#the-switch-statement) doesn't end with a jump statement such as: - -- [break](../statements/jump-statements.md#the-break-statement) -- [return](../statements/jump-statements.md#the-return-statement) -- [throw](../statements/exception-handling-statements.md#the-throw-statement) - -The following sample generates CS8070: - -```csharp -// CS8070.cs -public class MyClass -{ - public static void Main() - { - int i = 2; - int j = 0; - - switch (i) - { - case 1: - i++; - break; - - // Compiler error CS8070 is reported on the following line. - case 2: - i += 2; - // To resolve the error, uncomment one of the following example statements. - // break; - // return; - // throw new Exception("Fin"); - } - - switch (j) - { - case 1: - j++; - break; - - case 2: - j += 2; - break; - - // Compiler error CS8070 is reported on the following line. - default: - Console.WriteLine("Default"); - // To resolve the error, uncomment the following line: - // break; - } - } -} -``` diff --git a/docs/csharp/language-reference/compiler-messages/jump-statement-errors.md b/docs/csharp/language-reference/compiler-messages/jump-statement-errors.md index 758e183cb4696..f68580826b1dc 100644 --- a/docs/csharp/language-reference/compiler-messages/jump-statement-errors.md +++ b/docs/csharp/language-reference/compiler-messages/jump-statement-errors.md @@ -5,25 +5,37 @@ f1_keywords: - "CS0126" - "CS0127" - "CS0139" + - "CS0140" - "CS0153" + - "CS0157" + - "CS0158" - "CS0159" - "CS0161" + - "CS0162" - "CS0163" + - "CS0164" - "CS0469" + - "CS8070" - "CS9393" - "CS9394" helpviewer_keywords: - "CS0126" - "CS0127" - "CS0139" + - "CS0140" - "CS0153" + - "CS0157" + - "CS0158" - "CS0159" - "CS0161" + - "CS0162" - "CS0163" + - "CS0164" - "CS0469" + - "CS8070" - "CS9393" - "CS9394" -ms.date: 07/17/2026 +ms.date: 10/30/2026 ai-usage: ai-assisted --- # Resolve errors and warnings for jump statements @@ -31,84 +43,110 @@ ai-usage: ai-assisted This article covers the following compiler errors and warnings: -The following errors occur when you use a `break`, `continue`, `goto`, or `return` statement in a way that doesn't match the surrounding control flow: - -- [**CS0126**](#return-statement-values): *An object of a type convertible to 'type' is required* -- [**CS0127**](#return-statement-values): *Since 'method' returns void, a return keyword must not be followed by an object expression* -- [**CS0139**](#break-and-continue-targets): *No enclosing loop out of which to break or continue* -- [**CS0153**](#goto-statement-targets): *A goto case is only valid inside a switch statement* -- [**CS0159**](#goto-statement-targets): *No such label 'label' within the scope of the goto statement* -- [**CS0161**](#return-statement-values): *'method': not all code paths return a value* -- [**CS0163**](#switch-section-termination): *Control cannot fall through from one case label ('label') to another* -- [**CS9393**](#break-and-continue-targets): *No enclosing loop or switch statement with the label 'label' out of which to break* -- [**CS9394**](#break-and-continue-targets): *No enclosing loop with the label 'label' out of which to continue* - -The following warning occurs when a `goto case` statement targets a value that requires a conversion: - -- [**CS0469**](#goto-statement-targets): *The 'goto case' value is not implicitly convertible to type 'type'* - -## Break and continue targets +- [**CS0126**](#return-the-required-values): *An object of a type convertible to 'type' is required* +- [**CS0127**](#return-the-required-values): *Since 'method' returns void, a return keyword must not be followed by an object expression* +- [**CS0139**](#choose-valid-jump-targets): *No enclosing loop out of which to break or continue* +- [**CS0140**](#define-and-reference-labels-consistently): *The label 'label' is a duplicate* +- [**CS0153**](#choose-valid-jump-targets): *A goto case is only valid inside a switch statement* +- [**CS0157**](#choose-valid-jump-targets): *Control cannot leave the body of a finally clause* +- [**CS0158**](#define-and-reference-labels-consistently): *The label 'label' shadows another label by the same name in a contained scope* +- [**CS0159**](#choose-valid-jump-targets): *No such label 'label' within the scope of the goto statement* +- [**CS0161**](#return-the-required-values): *'method': not all code paths return a value* +- [**CS0162**](#remove-unreachable-code): *Unreachable code detected* +- [**CS0163**](#terminate-switch-sections-explicitly): *Control cannot fall through from one case label ('label') to another* +- [**CS0164**](#define-and-reference-labels-consistently): *This label has not been referenced* +- [**CS0469**](#choose-valid-jump-targets): *The 'goto case' value is not implicitly convertible to type 'type'* +- [**CS8070**](#terminate-switch-sections-explicitly): *Control cannot fall out of switch from final case label ('label')* +- [**CS9393**](#choose-valid-jump-targets): *No enclosing loop or switch statement with the label 'label' out of which to break* +- [**CS9394**](#choose-valid-jump-targets): *No enclosing loop with the label 'label' out of which to continue* + +## Choose valid jump targets - **CS0139**: *No enclosing loop out of which to break or continue* +- **CS0153**: *A goto case is only valid inside a switch statement* +- **CS0157**: *Control cannot leave the body of a finally clause* +- **CS0159**: *No such label 'label' within the scope of the goto statement* +- **CS0469**: *The 'goto case' value is not implicitly convertible to type 'type'* - **CS9393**: *No enclosing loop or switch statement with the label 'label' out of which to break* - **CS9394**: *No enclosing loop with the label 'label' out of which to continue* -The `break` statement transfers control out of the nearest enclosing loop or `switch` statement, and the `continue` statement starts the next iteration of the nearest enclosing loop. The compiler reports these diagnostics when it can't find that target. +- Place `break` inside a loop or `switch` statement, and place `continue` inside a loop. Each statement needs an enclosing construct to target (**CS0139**). +- Apply the label in `break label;` to an enclosing loop or `switch` statement (**CS9393**). Apply the label in `continue label;` to an enclosing loop, not a `switch` statement (**CS9394**). +- Place `goto case` and `goto default` inside the `switch` statement that contains their destination (**CS0153**). +- Define the named destination within the `goto` statement's scope, or correct the target name. A `goto` statement can't enter a nested block or another member (**CS0159**). +- Give a `goto case` value a type that's implicitly convertible to the `switch` governing type. For example, use `goto case (char)127;` rather than `goto case 127;` when the destination is a character case label (**CS0469**). +- Move a `return`, `break`, `continue`, or `goto` that exits a `finally` block outside that block. Jumps within the block are valid only when their targets also remain inside it (**CS0157**). -To resolve these errors: +See [Jump statements](../statements/jump-statements.md) and [The try-finally statement](../statements/exception-handling-statements.md#the-try-finally-statement) for the applicable control-flow rules. -- Place the `break` or `continue` statement inside a `while`, `do`, `for`, or `foreach` loop. A `break` statement can also appear in a `switch` section. A bare `break` or `continue` that isn't nested in one of these statements has no target (**CS0139**). -- When you write a labeled `break` (`break label;`), apply the same label to an enclosing loop or `switch` statement. The label must name a loop or `switch` that contains the `break` statement (**CS9393**). -- When you write a labeled `continue` (`continue label;`), apply the same label to an enclosing loop. A labeled `continue` can target only a loop, not a `switch` statement, because `continue` starts the next loop iteration (**CS9394**). +## Define and reference labels consistently -For more information about these statements, see [The `break` statement](../statements/jump-statements.md#the-break-statement) and [The `continue` statement](../statements/jump-statements.md#the-continue-statement) in the jump statements article. +- **CS0140**: *The label 'label' is a duplicate* +- **CS0158**: *The label 'label' shadows another label by the same name in a contained scope* +- **CS0164**: *This label has not been referenced* -## Goto statement targets +- Rename labels that have the same name in the same or nested scopes, and update the corresponding `goto` targets. Remove a duplicate label if the existing label already marks the intended destination (**CS0140**, **CS0158**). +- Remove an unused label while keeping its statement. If a `goto` was intended to reach that statement, correct its target label instead (**CS0164**). -- **CS0153**: *A goto case is only valid inside a switch statement* -- **CS0159**: *No such label 'label' within the scope of the goto statement* -- **CS0469**: *The 'goto case' value is not implicitly convertible to type 'type'* - -The `goto` statement transfers control to a labeled statement, to a `case` label, or to the `default` label of a `switch` statement. The compiler reports these diagnostics when the target label doesn't exist or isn't reachable from the `goto` statement. +For label scope and target resolution, see [The goto statement](../statements/jump-statements.md#the-goto-statement). -To resolve these errors: +## Terminate switch sections explicitly -- Use `goto case` and `goto default` only inside a `switch` statement. Both forms name a section of the enclosing `switch` statement, so they have no meaning outside one (**CS0153**). -- Add a label that matches the name in the `goto` statement, and confirm that the label is within the scope of the `goto` statement. A `goto` statement can't jump into a nested block, and `goto case` requires a matching `case` label in the same `switch` statement (**CS0159**). -- Give the `goto case` value the same type as the `switch` governing expression, or add an explicit cast so an implicit conversion exists. For example, use `goto case (char)127;` rather than `goto case 127;` when the `switch` governs a `char` value (**CS0469**). +- **CS0163**: *Control cannot fall through from one case label ('label') to another* +- **CS8070**: *Control cannot fall out of switch from final case label ('label')* -For more information about the `goto` statement, see [The `goto` statement](../statements/jump-statements.md#the-goto-statement) in the jump statements article. For more information about `goto case` and `goto default`, see [The `switch` statement](../statements/selection-statements.md#the-switch-statement) in the selection statements article. +Add a jump statement such as `break`, `return`, `goto case`, `goto default`, or `throw` wherever control could otherwise reach the end of a `switch` section. Control can't fall into the next section (**CS0163**) or out of the final section (**CS8070**), even when the `switch` has only one section. -## Switch section termination +The following examples generate **CS8070** at the marked final `case 1:` and `default:` labels. Uncomment the final `break;` in each `switch` to fix the error: -- **CS0163**: *Control cannot fall through from one case label ('label') to another* +```csharp +switch (number) +{ + case 0: + number++; + break; + case 1: // CS8070 + number = 0; + // break; +} -C# doesn't allow control to fall through from one `switch` section to the next. When a `switch` statement contains more than one section, you must explicitly terminate each section, including the last one. +switch (number) +{ + case 0: + number++; + break; + default: // CS8070 + number = 0; + // break; +} +``` -To resolve this error, end each `switch` section that contains statements with a jump statement, such as `break`, `return`, `goto case`, `goto default`, or `throw`. To run the same statements for more than one value, stack the `case` labels with no statements between them; that arrangement isn't fall-through. When you want one section to continue into another, use `goto case` or `goto default` to name the next section explicitly (**CS0163**). +To share statements between values, stack their `case` labels with no intervening statements. To transfer control to another section explicitly, use `goto case` or `goto default`. -For more information about the `switch` statement, see [The `switch` statement](../statements/selection-statements.md#the-switch-statement) in the selection statements article. For more information about the `throw` statement, see [The `throw` statement](../statements/exception-handling-statements.md#the-throw-statement) in the exception handling statements article. +See [The switch statement](../statements/selection-statements.md#the-switch-statement) and [The throw statement](../statements/exception-handling-statements.md#the-throw-statement). -## Return statement values +## Return the required values - **CS0126**: *An object of a type convertible to 'type' is required* - **CS0127**: *Since 'method' returns void, a return keyword must not be followed by an object expression* - **CS0161**: *'method': not all code paths return a value* -The `return` statement ends execution of the containing member and returns control to the caller. A `return` statement can also return a value. +- Supply an expression after `return` when the containing member requires a value, and make its type convertible to the required return type (**CS0126**). +- Use `return;` without an expression in a member that doesn't return a value, such as a `void` method or a property setter (**CS0127**). +- Cover every reachable exit from a value-returning member. Add a return for an uncovered branch, or throw when a branch can't produce a result (**CS0161**). + +For return forms and requirements, see [The return statement](../statements/jump-statements.md#the-return-statement). -To resolve these errors: +## Remove unreachable code -- Supply a value in each `return` statement of a member that has a non-`void` return type, and make sure the value is convertible to that return type. A `get` accessor and a value-returning method both require a `return` statement that includes a value (**CS0126**). -- Remove the value from any `return` statement in a member that returns `void`, such as a `set` accessor or a method with a `void` return type. Use a bare `return;` statement to exit early (**CS0127**). -- Make sure every code path in a value-returning member ends with a `return` statement or a `throw` statement. A member returns on all code paths when each branch of every conditional statement returns a value, or when a final `return` statement follows the conditional logic (**CS0161**). +- **CS0162**: *Unreachable code detected* -For more information about `return` statements in async methods and members that return `Task` or `ValueTask` types, see [Errors and warnings related to async and await](async-await-errors.md). For more information about `return` statements in iterators, see [Errors and warnings related to iterators](iterator-yield.md). +Remove statements that follow an unconditional jump when no control-flow path can reach them. For example, remove `break;` immediately after `return` in a `switch` section; the return already exits the member (**CS0162**). -For more information about the `return` statement, see [The `return` statement](../statements/jump-statements.md#the-return-statement) in the jump statements article. +If the statements were intended to execute, move them before the jump or correct the condition or jump target that makes them unreachable. See [Jump statements](../statements/jump-statements.md) for how each statement transfers control. ## C# language specification diff --git a/docs/csharp/language-reference/compiler-messages/nameof-errors.md b/docs/csharp/language-reference/compiler-messages/nameof-errors.md new file mode 100644 index 0000000000000..6eb9bd57df373 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/nameof-errors.md @@ -0,0 +1,53 @@ +--- +title: "Resolve errors and warnings related to nameof expressions" +description: "This article helps you diagnose and correct compiler errors and warnings related to nameof expressions" +f1_keywords: + - "CS8081" + - "CS8082" + - "CS8084" + - "CS8093" +helpviewer_keywords: + - "CS8081" + - "CS8082" + - "CS8084" + - "CS8093" +ms.date: 10/30/2026 +ai-usage: ai-assisted +--- + +# Resolve errors and warnings for nameof expressions + +This article covers the following compiler errors and warnings: + + + +- [**CS8081**](#use-an-expression-that-names-a-symbol): *Expression does not have a name.* +- [**CS8082**](#use-an-expression-that-names-a-symbol): *Sub-expression cannot be used in an argument to nameof.* +- [**CS8084**](#correct-method-group-references): *Type parameters are not allowed on a method group as an argument to 'nameof'.* +- [**CS8093**](#correct-method-group-references): *Extension method groups are not allowed as an argument to 'nameof'.* + +## Use an expression that names a symbol + +- **CS8081**: *Expression does not have a name.* +- **CS8082**: *Sub-expression cannot be used in an argument to nameof.* + +- Pass the name of a variable, type, or member rather than an expression that computes a value. For example, replace `nameof(value + 1)` with `nameof(value)` to get the variable's name (**CS8081**). +- Replace an invocation, element access, or other unsupported subexpression in a member reference with a type or variable name. For example, replace `nameof(GetText().Length)` with `nameof(string.Length)` to get the property's name without invoking a method (**CS8082**). + +For valid operand forms, see the [nameof expression](../operators/nameof.md). + +## Correct method-group references + +- **CS8084**: *Type parameters are not allowed on a method group as an argument to 'nameof'.* +- **CS8093**: *Extension method groups are not allowed as an argument to 'nameof'.* + +- Omit the method's type argument list. For a generic method declared as `Method()`, use `nameof(Method)` rather than `nameof(Method)` (**CS8084**). Naming a generic method is valid; supplying its type arguments in this form isn't. This restriction is separate from support for unbound generic *types*, such as `nameof(List<>)`, in C# 14 and later. +- Reference an extension method through the static class that declares it rather than through its receiver. For an extension method declared in `TextExtensions`, replace `nameof(text.Extension)` with `nameof(TextExtensions.Extension)` (**CS8093**). + +For extension method declaration and invocation forms, see [Extension members](../../programming-guide/classes-and-structs/extension-methods.md). + +## C# language specification + +For more information, see [The nameof operator](~/_csharpstandard/standard/expressions.md#12823-the-nameof-operator) in the C# language specification. diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index aa30d89e7898d..9de9f8502f8ea 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -677,12 +677,18 @@ items: href: ./compiler-messages/jump-statement-errors.md displayName: > break, continue, goto, return, labeled break, labeled continue, - CS0126, CS0127, CS0139, CS0153, CS0159, CS0161, CS0163, CS0469, CS9393, CS9394 + CS0126, CS0127, CS0139, CS0140, CS0153, CS0157, CS0158, CS0159, CS0161, CS0162, + CS0163, CS0164, CS0469, CS8070, CS9393, CS9394 - name: Throwing and catching exceptions href: ./compiler-messages/throwing-and-catching-exceptions.md displayName: > throw, catch, exception filter, catch filter, CS8359, CS8360 + - name: nameof expressions + href: ./compiler-messages/nameof-errors.md + displayName: > + nameof, expression names, method groups, + CS8081, CS8082, CS8084, CS8093 - name: Extension declarations href: ./compiler-messages/extension-declarations.md displayName: > @@ -980,8 +986,6 @@ items: href: ../misc/cs0135.md - name: CS0136 href: ../misc/cs0136.md - - name: CS0140 - href: ../misc/cs0140.md - name: CS0143 href: ../misc/cs0143.md - name: CS0145 @@ -1002,10 +1006,6 @@ items: href: ../misc/cs0155.md - name: CS0156 href: ../misc/cs0156.md - - name: CS0157 - href: ../misc/cs0157.md - - name: CS0158 - href: ../misc/cs0158.md - name: CS0160 href: ../misc/cs0160.md - name: CS0165 @@ -1582,8 +1582,6 @@ items: href: ./compiler-messages/cs7034.md - name: CS7035 href: ./compiler-messages/cs7035.md - - name: CS8070 - href: ./compiler-messages/cs8070.md - name: CS8092 href: ./compiler-messages/cs8092.md - name: CS8146 @@ -1778,10 +1776,6 @@ items: href: ./compiler-messages/cs0108.md - name: CS0114 href: ../misc/cs0114.md - - name: CS0162 - href: ../misc/cs0162.md - - name: CS0164 - href: ../misc/cs0164.md - name: CS0252 href: ../misc/cs0252.md - name: CS0253 diff --git a/docs/csharp/misc/cs0140.md b/docs/csharp/misc/cs0140.md deleted file mode 100644 index 5df84617ab67e..0000000000000 --- a/docs/csharp/misc/cs0140.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -description: "Compiler Error CS0140" -title: "Compiler Error CS0140" -ms.date: 07/20/2015 -f1_keywords: - - "CS0140" -helpviewer_keywords: - - "CS0140" -ms.assetid: 61787b8a-7b69-41c1-8ee3-87f619698594 ---- -# Compiler Error CS0140 - -The label 'label' is a duplicate - - A label with the same name appeared twice. For more information, see [goto](../language-reference/statements/jump-statements.md#the-goto-statement). - - The following sample generates CS0140: - -```csharp -// CS0140.cs -namespace MyNamespace -{ - public class MyClass - { - public static void Main() - { - label1: int i = 0; - label1: int j = 0; // CS0140, comment this line to resolve - goto label1; - } - } -} -``` diff --git a/docs/csharp/misc/cs0157.md b/docs/csharp/misc/cs0157.md deleted file mode 100644 index 1222b717da2e6..0000000000000 --- a/docs/csharp/misc/cs0157.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -description: "Compiler Error CS0157" -title: "Compiler Error CS0157" -ms.date: 07/20/2015 -f1_keywords: - - "CS0157" -helpviewer_keywords: - - "CS0157" -ms.assetid: a5d9d506-81f8-47dd-85b6-85f8170bcbef ---- -# Compiler Error CS0157 - -Control cannot leave the body of a finally clause - - All of the statements in a [finally](../language-reference/statements/exception-handling-statements.md#the-try-finally-statement) clause must execute. For more information, see [Exceptions and Exception Handling](../fundamentals/exceptions/index.md). - - The following sample generates CS0157: - -```csharp -// CS0157.cs -using System; -namespace MyNamespace -{ - public class MyClass2 : Exception - { - } - - public class MyClass - { - public static void Main() - { - try - { - } - finally - { - return; // CS0157, cannot leave finally clause - } - } - } -} -``` diff --git a/docs/csharp/misc/cs0158.md b/docs/csharp/misc/cs0158.md deleted file mode 100644 index eae02b580fa49..0000000000000 --- a/docs/csharp/misc/cs0158.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -description: "Compiler Error CS0158" -title: "Compiler Error CS0158" -ms.date: 07/20/2015 -f1_keywords: - - "CS0158" -helpviewer_keywords: - - "CS0158" -ms.assetid: 88ac61a9-ce55-4272-9141-0873765a7034 ---- -# Compiler Error CS0158 - -The label 'label' shadows another label by the same name in a contained scope - - A label in an inner scope hides a label with the same name in an outer scope. For more information, see [goto](../language-reference/statements/jump-statements.md#the-goto-statement). - - The following sample generates CS0158: - -```csharp -// CS0158.cs -namespace MyNamespace -{ - public class MyClass - { - public static void Main() - { - goto lab1; - lab1: - { - lab1: - goto lab1; // CS0158 - } - } - } -} -``` diff --git a/docs/csharp/misc/cs0162.md b/docs/csharp/misc/cs0162.md deleted file mode 100644 index 852f7ae3328fe..0000000000000 --- a/docs/csharp/misc/cs0162.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -description: "Compiler Warning (level 2) CS0162" -title: "Compiler Warning (level 2) CS0162" -ms.date: 07/20/2015 -f1_keywords: - - "CS0162" -helpviewer_keywords: - - "CS0162" -ms.assetid: 369b5b02-a9cc-404b-b758-4184285af2de ---- -# Compiler Warning (level 2) CS0162 - -Unreachable code detected - -The compiler detected code that will never be executed. - -## Example - -The following example generates CS0162: - -```csharp -// CS0162.cs -// compile with: /W:2 -public class Program -{ - public static void Main() - { - goto lab1; - { - // The following statements cannot be reached: - int i = 9; // CS0162 - i++; - } - lab1: - { - } - } -} -``` - -Another common example where this error is generated is as follows: - -```csharp -public static class Class1 -{ - public static string Method1() - { - string x = "a"; - switch (x) - { - case "a": - return "a"; - break; // CS0162 - } - return ""; - } -} -``` - -The `break` statement cannot be reached because it occurs after the `return` statement. -The `return` statement ends the enclosing `case` branch. diff --git a/docs/csharp/misc/cs0164.md b/docs/csharp/misc/cs0164.md deleted file mode 100644 index 401baaf87b132..0000000000000 --- a/docs/csharp/misc/cs0164.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -description: "Compiler Warning (level 2) CS0164" -title: "Compiler Warning (level 2) CS0164" -ms.date: 09/07/2019 -f1_keywords: - - "CS0164" -helpviewer_keywords: - - "CS0164" -ms.assetid: c701265b-ea7d-4d56-ae73-f74e039f1005 ---- -# Compiler Warning (level 2) CS0164 - -This label has not been referenced - - A label was declared but never used. - - The following sample generates CS0164: - -```csharp -// CS0164.cs -// compile with: /W:2 -public class Program -{ - public static void Main() - { - int i = 0; - l1: // CS0164 - i++; - // Uncomment the following lines to resolve this warning. - // if (i < 10) - // goto l1; - } -} -``` diff --git a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md index e0aa6a17d4add..e5046c3235d24 100644 --- a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md +++ b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md @@ -76,7 +76,6 @@ f1_keywords: - "CS7064" - "CS7065" - "CS7070" - - "CS7084" - "CS7086" - "CS7087" - "CS7089" @@ -112,14 +111,8 @@ f1_keywords: - "CS8036" - "CS8055" - "CS8057" - - "CS8058" - - "CS8070" - "CS8078" # build only diagnostic - "CS8079" - - "CS8081" - - "CS8082" - - "CS8084" - - "CS8093" - "CS8095" - "CS8096" - "CS8099"