Skip to content

Commit dd6bf71

Browse files
pkulikovBillWagner
andauthored
C# reference: Consolidate the selection statements articles (#25520)
* C# reference: Consolidate the selection statements articles * Update docs/csharp/language-reference/statements/selection-statements.md Co-authored-by: Bill Wagner <[email protected]> * Update docs/csharp/language-reference/statements/selection-statements.md Co-authored-by: Bill Wagner <[email protected]> * Update docs/csharp/language-reference/statements/selection-statements.md Co-authored-by: Bill Wagner <[email protected]> * Update docs/csharp/language-reference/statements/selection-statements.md Co-authored-by: Bill Wagner <[email protected]> * Review based on feedback Co-authored-by: Bill Wagner <[email protected]>
1 parent f260523 commit dd6bf71

File tree

52 files changed

+384
-1411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+384
-1411
lines changed

.openpublishing.redirection.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,10 @@
14391439
"source_path": "docs/csharp/language-reference/keywords/global.md",
14401440
"redirect_url": "/dotnet/csharp/language-reference/operators/namespace-alias-qualifier"
14411441
},
1442+
{
1443+
"source_path": "docs/csharp/language-reference/keywords/if-else.md",
1444+
"redirect_url": "/dotnet/csharp/language-reference/statements/selection-statements"
1445+
},
14421446
{
14431447
"source_path": "docs/csharp/language-reference/keywords/implicit-numeric-conversions-table.md",
14441448
"redirect_url": "/dotnet/csharp/language-reference/builtin-types/numeric-conversions"
@@ -1521,7 +1525,7 @@
15211525
},
15221526
{
15231527
"source_path": "docs/csharp/language-reference/keywords/selection-statements.md",
1524-
"redirect_url": "/dotnet/csharp/language-reference/keywords/statement-keywords"
1528+
"redirect_url": "/dotnet/csharp/language-reference/statements/selection-statements"
15251529
},
15261530
{
15271531
"source_path": "docs/csharp/language-reference/keywords/short.md",
@@ -1543,6 +1547,10 @@
15431547
"source_path": "docs/csharp/language-reference/keywords/struct.md",
15441548
"redirect_url": "/dotnet/csharp/language-reference/builtin-types/struct"
15451549
},
1550+
{
1551+
"source_path": "docs/csharp/language-reference/keywords/switch.md",
1552+
"redirect_url": "/dotnet/csharp/language-reference/statements/selection-statements"
1553+
},
15461554
{
15471555
"source_path": "docs/csharp/language-reference/keywords/true-false-operators.md",
15481556
"redirect_url": "/dotnet/csharp/language-reference/operators/true-false-operators"

docs/csharp/fundamentals/functional/discards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ Without assigning the task to a discard, the following code generates a compiler
7979

8080
- [Deconstructing tuples and other types](deconstruct.md)
8181
- [`is` operator](../../language-reference/operators/is.md)
82-
- [`switch` keyword](../../language-reference/keywords/switch.md)
82+
- [`switch` expression](../../language-reference/operators/switch-expression.md)

docs/csharp/fundamentals/tutorials/classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ You can continue with the [object oriented programming](oop.md) tutorial.
215215

216216
You can learn more about these concepts in these articles:
217217

218-
- [If and else statement](../../language-reference/keywords/if-else.md)
218+
- [Selection statements](../../language-reference/statements/selection-statements.md)
219219
- [Iteration statements](../../language-reference/statements/iteration-statements.md)

docs/csharp/fundamentals/tutorials/pattern-matching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace toll_calculator
8282
}
8383
```
8484

85-
The preceding code uses a [`switch` expression](../../language-reference/operators/switch-expression.md) (not the same as a [`switch`](../../language-reference/keywords/switch.md) statement) that tests the [declaration pattern](../../language-reference/operators/patterns.md#declaration-and-type-patterns). A **switch expression** begins with the variable, `vehicle` in the preceding code, followed by the `switch` keyword. Next comes all the **switch arms** inside curly braces. The `switch` expression makes other refinements to the syntax that surrounds the `switch` statement. The `case` keyword is omitted, and the result of each arm is an expression. The last two arms show a new language feature. The `{ }` case matches any non-null object that didn't match an earlier arm. This arm catches any incorrect types passed to this method. The `{ }` case must follow the cases for each vehicle type. If the order were reversed, the `{ }` case would take precedence. Finally, the `null` [constant pattern](../../language-reference/operators/patterns.md#constant-pattern) detects when `null` is passed to this method. The `null` pattern can be last because the other patterns match only a non-null object of the correct type.
85+
The preceding code uses a [`switch` expression](../../language-reference/operators/switch-expression.md) (not the same as a [`switch` statement](../../language-reference/statements/selection-statements.md#the-switch-statement)) that tests the [declaration pattern](../../language-reference/operators/patterns.md#declaration-and-type-patterns). A **switch expression** begins with the variable, `vehicle` in the preceding code, followed by the `switch` keyword. Next comes all the **switch arms** inside curly braces. The `switch` expression makes other refinements to the syntax that surrounds the `switch` statement. The `case` keyword is omitted, and the result of each arm is an expression. The last two arms show a new language feature. The `{ }` case matches any non-null object that didn't match an earlier arm. This arm catches any incorrect types passed to this method. The `{ }` case must follow the cases for each vehicle type. If the order were reversed, the `{ }` case would take precedence. Finally, the `null` [constant pattern](../../language-reference/operators/patterns.md#constant-pattern) detects when `null` is passed to this method. The `null` pattern can be last because the other patterns match only a non-null object of the correct type.
8686

8787
You can test this code using the following code in `Program.cs`:
8888

docs/csharp/language-reference/builtin-types/bool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ms.assetid: 551cfe35-2632-4343-af49-33ad12da08e2
1818

1919
The `bool` type keyword is an alias for the .NET <xref:System.Boolean?displayProperty=nameWithType> structure type that represents a Boolean value, which can be either `true` or `false`.
2020

21-
To perform logical operations with values of the `bool` type, use [Boolean logical](../operators/boolean-logical-operators.md) operators. The `bool` type is the result type of [comparison](../operators/comparison-operators.md) and [equality](../operators/equality-operators.md) operators. A `bool` expression can be a controlling conditional expression in the [if](../keywords/if-else.md), [do](../statements/iteration-statements.md#the-do-statement), [while](../statements/iteration-statements.md#the-while-statement), and [for](../statements/iteration-statements.md#the-for-statement) statements and in the [conditional operator `?:`](../operators/conditional-operator.md).
21+
To perform logical operations with values of the `bool` type, use [Boolean logical](../operators/boolean-logical-operators.md) operators. The `bool` type is the result type of [comparison](../operators/comparison-operators.md) and [equality](../operators/equality-operators.md) operators. A `bool` expression can be a controlling conditional expression in the [if](../statements/selection-statements.md#the-if-statement), [do](../statements/iteration-statements.md#the-do-statement), [while](../statements/iteration-statements.md#the-while-statement), and [for](../statements/iteration-statements.md#the-for-statement) statements and in the [conditional operator `?:`](../operators/conditional-operator.md).
2222

2323
The default value of the `bool` type is `false`.
2424

docs/csharp/language-reference/builtin-types/enum.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,5 @@ For more information, see the following sections of the [C# language specificati
8585
- [Enumeration format strings](../../../standard/base-types/enumeration-format-strings.md)
8686
- [Design guidelines - Enum design](../../../standard/design-guidelines/enum.md)
8787
- [Design guidelines - Enum naming conventions](../../../standard/design-guidelines/names-of-classes-structs-and-interfaces.md#naming-enumerations)
88-
- [switch statement](../keywords/switch.md)
88+
- [`switch` expression](../operators/switch-expression.md)
89+
- [`switch` statement](../statements/selection-statements.md#the-switch-statement)

docs/csharp/language-reference/compiler-messages/cs0151.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,3 @@ public class MyClass
4646
}
4747
}
4848
```
49-
50-
## Example of void method
51-
52-
A [void](../builtin-types/void.md) method invocation in a [switch](../keywords/switch.md) match expression generates CS0151. You can fix the error by calling a method that returns an integral type such as [int](../builtin-types/integral-numeric-types.md) or [long](../builtin-types/integral-numeric-types.md) instead.
53-
54-
```csharp
55-
class C
56-
{
57-
static void Main()
58-
{
59-
switch (M()) // CS0151
60-
{
61-
default:
62-
break;
63-
}
64-
}
65-
66-
static void M()
67-
{
68-
}
69-
}
70-
```

docs/csharp/language-reference/compiler-messages/cs0163.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.assetid: 00139dcf-33cd-45ea-bf80-d6f26b10a5d2
1212

1313
Control cannot fall through from one case label ('label') to another
1414

15-
When a [switch statement](../keywords/switch.md) contains more than one switch section, you must explicitly terminate each section, including the last one, by using one of the following keywords:
15+
When a [switch statement](../statements/selection-statements.md#the-switch-statement) contains more than one switch section, you must explicitly terminate each section, including the last one, by using one of the following keywords:
1616

1717
- [return](../keywords/return.md)
1818

@@ -22,9 +22,7 @@ Control cannot fall through from one case label ('label') to another
2222

2323
- [throw](../keywords/throw.md)
2424

25-
- [continue](../keywords/continue.md)
26-
27-
If you want to implement "fall through" behavior from one section to the next, use `goto case #`. For more information and examples, see [switch](../keywords/switch.md).
25+
If you want to implement "fall through" behavior from one section to the next, use `goto case #`.
2826

2927
The following sample generates CS0163.
3028

docs/csharp/language-reference/keywords/break.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.assetid: be2571ed-efb0-4965-b122-81e5b09db0b9
1111
---
1212
# break (C# Reference)
1313

14-
The `break` statement terminates the closest enclosing loop or [switch](./switch.md) statement in which it appears. Control is passed to the statement that follows the terminated statement, if any.
14+
The `break` statement terminates the closest enclosing loop or [`switch` statement](../statements/selection-statements.md#the-switch-statement) in which it appears. Control is passed to the statement that follows the terminated statement, if any.
1515

1616
## Example 1
1717

@@ -21,7 +21,7 @@ In this example, the conditional statement contains a counter that is supposed t
2121

2222
## Example 2
2323

24-
This example demonstrates the use of `break` in a [switch](./switch.md) statement.
24+
This example demonstrates the use of `break` in a `switch` statement.
2525

2626
[!code-csharp[csrefKeywordsJump#2](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsJump/CS/csrefKeywordsJump.cs#2)]
2727

@@ -40,7 +40,7 @@ In this example, the `break` statement is used to break out of an inner nested l
4040

4141
## Example 4
4242

43-
In this example, the `break` statement is only used to break out of the current branch during each iteration of the loop. The loop itself is unaffected by the instances of `break` that belong to the nested [switch](./switch.md) statement.
43+
In this example, the `break` statement is only used to break out of the current branch during each iteration of the loop. The loop itself is unaffected by the instances of `break` that belong to the nested `switch` statement.
4444

4545
[!code-csharp[csrefKeywordsJump#8](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsJump/CS/csrefKeywordsJump.cs#8)]
4646

@@ -53,4 +53,4 @@ In this example, the `break` statement is only used to break out of the current
5353
- [C# Reference](../index.md)
5454
- [C# Programming Guide](../../programming-guide/index.md)
5555
- [C# Keywords](./index.md)
56-
- [switch](./switch.md)
56+
- [`switch` statement](../statements/selection-statements.md#the-switch-statement)
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: "default - C# Reference"
3-
title: "default - C# Reference"
2+
description: "default - C# reference"
3+
title: "default - C# reference"
44
ms.date: 04/28/2021
55
f1_keywords:
66
- "default"
@@ -9,16 +9,15 @@ helpviewer_keywords:
99
ms.assetid: 14c48aaa-7d35-4058-a1a4-f53353050579
1010
---
1111

12-
# default (C# Reference)
12+
# default (C# reference)
1313

14-
The `default` keyword can be used in three ways:
14+
You can use the `default` keyword in the following contexts:
1515

16-
- To specify the default label in the [`switch` statement](switch.md).
16+
- To specify the default case in the [`switch` statement](../statements/selection-statements.md#the-switch-statement).
1717
- As the [default operator or literal](../operators/default.md) to produce the default value of a type.
1818
- As the [`default` type constraint](where-generic-type-constraint.md) on a generic method override or explicit interface implementation.
1919

2020
## See also
2121

22-
- [C# Reference](../index.md)
23-
- [C# Programming Guide](../../programming-guide/index.md)
24-
- [C# Keywords](index.md)
22+
- [C# reference](../index.md)
23+
- [C# keywords](index.md)

0 commit comments

Comments
 (0)