Skip to content

Commit 154ac89

Browse files
committed
Proofread
1 parent c4a5471 commit 154ac89

File tree

10 files changed

+48
-51
lines changed

10 files changed

+48
-51
lines changed

docs/csharp/language-reference/builtin-types/ref-struct.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ You can use the `ref` modifier in the declaration of a [structure type](struct.m
1212
- A `ref struct` can't implement interfaces.
1313
- A `ref struct` can't be boxed to <xref:System.ValueType?displayProperty=nameWithType> or <xref:System.Object?displayProperty=nameWithType>.
1414
- A `ref struct` can't be a type argument.
15-
- A `ref struct` variable can't be captured by a [lambda expression](../operators/lambda-expressions.md) or a [local function](../../programming-guide/classes-and-structs/local-functions.md).
16-
- A `ref struct` variable can't be used in the same block as the [`await`](../operators/await.md) expression in an [`async`](../keywords/async.md) method. Prior to C# 13, `ref struct` variables can't be used in an `async` method. However, you can use `ref struct` variables in synchronous methods, for example, in methods that return <xref:System.Threading.Tasks.Task> or <xref:System.Threading.Tasks.Task%601>.
17-
- Prior to C# 13, a `ref struct` variable can't be used in [iterators](../../iterators.md). Beginning with C# 13, `ref struct` types and `ref` locals may be used in iterators, provided they are not in code segments with the `yield return` statement.
15+
- A `ref struct` variable can't be captured in a [lambda expression](../operators/lambda-expressions.md) or a [local function](../../programming-guide/classes-and-structs/local-functions.md).
16+
- A `ref struct` variable can't be used in the same block as the [`await`](../operators/await.md) expression in an [`async`](../keywords/async.md) method. Before C# 13, `ref struct` variables can't be used in an `async` method. However, you can use `ref struct` variables in synchronous methods, for example, in methods that return <xref:System.Threading.Tasks.Task> or <xref:System.Threading.Tasks.Task%601>.
17+
- Before C# 13, a `ref struct` variable can't be used in [iterators](../../iterators.md). Beginning with C# 13, `ref struct` types and `ref` locals can be used in iterators, provided they aren't in code segments with the `yield return` statement.
1818

1919
You can define a disposable `ref struct`. To do that, ensure that a `ref struct` fits the [disposable pattern](~/_csharplang/proposals/csharp-8.0/using.md#pattern-based-using). That is, it has an instance `Dispose` method, which is accessible, parameterless and has a `void` return type. You can use the [using statement or declaration](../statements/using.md) with an instance of a disposable `ref struct`.
2020

@@ -34,13 +34,13 @@ Beginning with C# 11, you can declare a `ref` field in a `ref struct`, as the fo
3434

3535
:::code language="csharp" source="snippets/shared/StructType.cs" id="SnippetRefField":::
3636

37-
A `ref` field may have the `null` value. Use the <xref:System.Runtime.CompilerServices.Unsafe.IsNullRef%60%601(%60%600@)?displayProperty=nameWithType> method to determine if a `ref` field is `null`.
37+
A `ref` field can have the `null` value. Use the <xref:System.Runtime.CompilerServices.Unsafe.IsNullRef%60%601(%60%600@)?displayProperty=nameWithType> method to determine if a `ref` field is `null`.
3838

3939
You can apply the `readonly` modifier to a `ref` field in the following ways:
4040

4141
- `readonly ref`: You can [ref reassign](../operators/assignment-operator.md#ref-assignment) such a field with the `= ref` operator only inside a constructor or an [`init` accessor](../keywords/init.md). You can assign a value with the `=` operator at any point allowed by the field access modifier.
42-
- `ref readonly`: At any point, you cannot assign a value with the `=` operator to such a field. However, you can ref reassign a field with the `= ref` operator.
43-
- `readonly ref readonly`: You can only ref reassign such a field in a constructor or an `init` accessor. At any point, you cannot assign a value to the field.
42+
- `ref readonly`: At any point, you can't assign a value with the `=` operator to such a field. However, you can ref reassign a field with the `= ref` operator.
43+
- `readonly ref readonly`: You can only ref reassign such a field in a constructor or an `init` accessor. At any point, you can't assign a value to the field.
4444

4545
The compiler ensures that a reference stored in a `ref` field doesn't outlive its referent.
4646

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Cannot await in the body of a lock statement
1313

1414
## Example
1515

16-
The following sample generates CS1996:
16+
The following sample generates CS1996:
1717

1818
```csharp
1919
public class C
@@ -33,11 +33,11 @@ public class C
3333
}
3434
```
3535

36-
This code still generates this error with C# 13, as the `await` is in the `lock` statement block.
36+
The preceding code produces the same error with C# 13, as the `await` is in the `lock` statement block.
3737

3838
## To correct this error
3939

40-
Asynchronous code within a `lock` statement block is hard to implement reliably and even harder to implement in a general sense. The C# compiler doesn't support doing this to avoid emitting code that will be prone to deadlocks. Extracting the asynchronous code from the `lock` statement block will correct this error. For example:
40+
Asynchronous code within a `lock` statement block is hard to implement reliably and even harder to implement in a general sense. The C# compiler doesn't support doing this to avoid emitting code prone to deadlocks. Extracting the asynchronous code from the `lock` statement block corrects this error. For example:
4141

4242
```csharp
4343
public class C

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Compiler Error CS4004"
33
title: "Compiler Error CS4004"
4-
ms.date: 9/12/2022
4+
ms.date: 07/01/20242
55
f1_keywords:
66
- "CS4004"
77
helpviewer_keywords:
@@ -13,7 +13,7 @@ Cannot await in an unsafe context
1313

1414
## Example
1515

16-
The following sample generates CS4004:
16+
The following sample generates CS4004:
1717

1818
```csharp
1919
using System.Threading.Tasks;
@@ -53,7 +53,7 @@ The `ReverseText` method naively uses a background task to asynchronously create
5353

5454
## To correct this error
5555

56-
Separating the unsafe code from the awaitable code will correct this error. One separation technique is creating a new method for the unsafe code and then calling it from the awaitable code. For example:
56+
Separating the unsafe code from the awaitable code corrects this error. One separation technique is creating a new method for the unsafe code and then calling it from the awaitable code. For example:
5757

5858
```csharp
5959
public static class C

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ helpviewer_keywords:
1111

1212
Instance of type cannot be used inside a nested function, query expression, iterator block or async method
1313

14-
Beginning with C# 13, `ref struct` types can be used in iterator methods, provided that they are not in scope during a `yield return` statement.
14+
Beginning with C# 13, `ref struct` types can be used in iterator methods, if they aren't accessed across `yield return` statement.
1515

1616
## Example
1717

@@ -40,7 +40,7 @@ This enumerator method extracts lines of text from a character array. It naivel
4040

4141
## To correct this error
4242

43-
`Lines(char[] text)` is an enumerator function. An enumerator function compiles the method's body into a state machine that manages the sequence of states the iterator function goes through while processing. That state machine is implemented as a generated class, and the state is implemented as variables within that class. That captured local state is forced from a stack context to a heap context. Since `ref struct`s like `ReadOnlySpan<T>` cannot be stored in the heap, the CS4013 error is raised. To continue to use a `ReadOnlySpan<T>`, to correct this error, the method must be re-implemented as a non-iterator function, for example:
43+
`Lines(char[] text)` is an enumerator function. An enumerator function compiles the method's body into a state machine that manages the sequence of states the iterator function goes through while processing. That state machine is implemented as a generated class, and the state is implemented as variables within that class. That captured local state is forced from a stack context to a heap context. Since `ref struct`s like `ReadOnlySpan<T>` can't be stored in the heap, the CS4013 error is raised. To continue to use a `ReadOnlySpan<T>`, to correct this error, the method must be reimplemented as a noniterator function, for example:
4444

4545
```csharp
4646
public static IEnumerable<string> Lines2(char[] text)
@@ -61,7 +61,7 @@ This enumerator method extracts lines of text from a character array. It naivel
6161
}
6262
```
6363

64-
To continue to use an iterator function, to correct this error, the method must be re-implemented to avoid using `ReadOnlySpan<T>`, for example:
64+
To continue to use an iterator function, to correct this error, the method must be reimplemented to avoid using `ReadOnlySpan<T>`, for example:
6565

6666
```csharp
6767
public static IEnumerable<string> Lines2(char[] chars)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ helpviewer_keywords:
1111

1212
Iterators cannot have by-reference locals
1313

14-
Iterator blocks use deferred execution, where the evaluation of an expression is delayed until its realized value is actually required. To manage that deferred execution state, iterator blocks use a state machine, capturing variable state in closures implemented in compiler-generated classes and properties. A local variable reference (on the stack) cannot be captured within the instance of a class in the heap, so the compiler issues an error.
14+
Iterator blocks use deferred execution, where the evaluation of an expression is delayed until its realized value is required. To manage that deferred execution state, iterator blocks use a state machine, capturing variable state in closures implemented in compiler-generated classes and properties. A local variable reference (on the stack) can't be captured within the instance of a class in the heap, so the compiler issues an error.
1515

1616
Beginning with C# 13, this restriction was removed.
1717

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ helpviewer_keywords:
1111

1212
Async methods cannot have by-reference locals
1313

14-
To manage asynchronous state, `async` methods use a state machine, capturing variable state in closures implemented in compiler-generated classes and properties. A local variable reference (on the stack) cannot be captured within the instance of a class in the heap, so the compiler issues an error.
14+
To manage asynchronous state, `async` methods use a state machine, capturing variable state in closures implemented in compiler-generated classes and properties. A local variable reference (on the stack) can't be captured within the instance of a class in the heap, so the compiler issues an error.
1515

1616
## Example
1717

18-
The following sample generates CS8177 in C# prior to C# 13:
18+
The following sample generates CS8177 before C# 13:
1919

2020
```csharp
2121
// CS8177.cs (20,26)

docs/csharp/language-reference/compiler-messages/warning-waves.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Compiler warning waves"
3-
description: "C# warning waves are optional warnings that can be reported on code where previously a warning wouldn't have been reported. They represent practices that could be harmful, or potentially elements that may be breaking changes in the future."
3+
description: "C# warning waves are optional warnings that can be reported on code where previously a warning wouldn't have been reported. They represent practices that could be harmful, or potentially elements that might be breaking changes in the future."
44
ms.date: 07/01/2024
55
f1_keywords:
66
- "CS7023"
@@ -39,7 +39,7 @@ helpviewer_keywords:
3939
---
4040
# C# Warning waves
4141

42-
New warnings and errors may be introduced in each release of the C# compiler. When new warnings could be reported on existing code, those warnings are introduced under an opt-in system referred to as a *warning wave*. The opt-in system means that you shouldn't see new warnings on existing code without taking action to enable them. Warning waves are enabled using the [**AnalysisLevel**](../compiler-options/errors-warnings.md#analysis-level) element in your project file. When `<TreatWarningsAsErrors>true</TreatWarningsAsErrors>` is specified, enabled warning wave warnings generate errors. Warning wave 5 diagnostics were added in C# 9. Warning wave 6 diagnostics were added in C# 10. Warning wave 7 diagnostics were added in C# 11. Warning wave 8 diagnostics were added in C# 12.
42+
New warnings and errors can be introduced in each release of the C# compiler. When new warnings could be reported on existing code, those warnings are introduced under an opt-in system referred to as a *warning wave*. The opt-in system means that you shouldn't see new warnings on existing code without taking action to enable them. Warning waves are enabled using the [**AnalysisLevel**](../compiler-options/errors-warnings.md#analysis-level) element in your project file. When `<TreatWarningsAsErrors>true</TreatWarningsAsErrors>` is specified, enabled warning wave warnings generate errors. Warning wave 5 diagnostics were added in C# 9. Warning wave 6 diagnostics were added in C# 10. Warning wave 7 diagnostics were added in C# 11. Warning wave 8 diagnostics were added in C# 12.
4343

4444
## CS9123 - Taking address of local or parameter in async method can create a GC hole.
4545

@@ -66,7 +66,7 @@ You can address this warning by renaming the type to include at least one non-lo
6666

6767
*Warning wave 6*
6868

69-
This warning corrects some inconsistencies in reporting differences between partial method signatures. The compiler always reported an error when the partial method signatures created different CLR signatures. Now, the compiler reports CS8826 when the signatures are syntactically different C#. Consider the following partial class:
69+
This warning corrects some inconsistencies in reporting differences between partial method signatures. The compiler always reported an error when the partial method signatures created different CLR signatures. Now, the compiler reports CS8826 when the signatures are syntactically different C#. Consider the following partial class:
7070

7171
:::code language="csharp" source="./snippets/WarningWaves/WaveSix.cs" id="PartialMethodDeclaration":::
7272

@@ -87,7 +87,7 @@ The `is` and `as` expressions always return `false` for a static type because yo
8787

8888
:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StaticTypeAsIs":::
8989

90-
The compiler reports this warning because the type test can never succeed. To correct this warning, remove the test and remove any code executed only if the test succeeded. In the preceding example, the `else` clause is always executed. The method body could be replaced by that single line:
90+
The compiler reports this warning because the type test can never succeed. To correct this warning, remove the test and remove any code executed only if the test succeeded. In the preceding example, the `else` clause is always executed. You can replace that method body with that single line:
9191

9292
```csharp
9393
Console.WriteLine("o is not an instance of a static class");
@@ -97,7 +97,7 @@ Console.WriteLine("o is not an instance of a static class");
9797

9898
*Warning wave 5*
9999

100-
The `==` and `!=` operators always return `false` (or `true`) when comparing an instance of a `struct` type to `null`. The following code demonstrates this warning. Assume `S` is a `struct` that has defined `operator ==` and `operator !=`:
100+
The `==` and `!=` operators always return `false` (or `true`) when comparing an instance of a `struct` type to `null`. The following code demonstrates this warning. Assume `S` is a `struct` that defines `operator ==` and `operator !=`:
101101

102102
:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StructsArentNull":::
103103

@@ -115,7 +115,7 @@ To fix this error, put parentheses around the query expression:
115115

116116
:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="QueryPrecedenceNoWarn":::
117117

118-
## Members must be fully assigned, use of unassigned variable (CS8880, CS8881, CS8882, CS8883, CS8884, CS8885, CS8886, CS8887)
118+
## Members must be fully assigned. Use of unassigned variable (CS8880, CS8881, CS8882, CS8883, CS8884, CS8885, CS8886, CS8887)
119119

120120
*Warning wave 5*
121121

docs/csharp/language-reference/statements/yield.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ You use the `yield` statement in an [iterator](../../iterators.md) to provide th
2222

2323
Iteration also finishes when control reaches the end of an iterator.
2424

25-
In the preceding examples, the return type of iterators is <xref:System.Collections.Generic.IEnumerable%601> (in non-generic cases, use <xref:System.Collections.IEnumerable> as the return type of an iterator). You can also use <xref:System.Collections.Generic.IAsyncEnumerable%601> as the return type of an iterator. That makes an iterator async. Use the [`await foreach` statement](iteration-statements.md#await-foreach) to iterate over iterator's result, as the following example shows:
25+
In the preceding examples, the return type of iterators is <xref:System.Collections.Generic.IEnumerable%601> (in nongeneric cases, use <xref:System.Collections.IEnumerable> as the return type of an iterator). You can also use <xref:System.Collections.Generic.IAsyncEnumerable%601> as the return type of an iterator. That makes an iterator async. Use the [`await foreach` statement](iteration-statements.md#await-foreach) to iterate over iterator's result, as the following example shows:
2626

2727
:::code language="csharp" source="snippets/yield/Program.cs" id="IteratorAsync":::
2828

29-
<xref:System.Collections.Generic.IEnumerator%601> or <xref:System.Collections.IEnumerator> can also be the return type of an iterator. That is useful when you implement the `GetEnumerator` method in the following scenarios:
29+
<xref:System.Collections.Generic.IEnumerator%601> or <xref:System.Collections.IEnumerator> can also be the return type of an iterator. Use those return types when you implement the `GetEnumerator` method in the following scenarios:
3030

3131
- You design the type that implements <xref:System.Collections.Generic.IEnumerable%601> or <xref:System.Collections.IEnumerable> interface.
3232
- You add an instance or [extension](../../programming-guide/classes-and-structs/extension-methods.md) `GetEnumerator` method to enable iteration over the type's instance with the [`foreach` statement](iteration-statements.md#the-foreach-statement), as the following example shows:
@@ -37,7 +37,7 @@ You can't use the `yield` statements in:
3737

3838
- methods with [in](../keywords/method-parameters.md#in-parameter-modifier), [ref](../keywords/ref.md), or [out](../keywords/method-parameters.md#out-parameter-modifier) parameters
3939
- [lambda expressions](../operators/lambda-expressions.md) and [anonymous methods](../operators/delegate-operator.md)
40-
- [unsafe blocks](../keywords/unsafe.md). Prior to C# 13, `yield` was invalid in any method with an `unsafe` block. Beginning with C# 13, you can use `yield` in methods with `unsafe` blocks, but not in the `unsafe` block.
40+
- [unsafe blocks](../keywords/unsafe.md). Before C# 13, `yield` was invalid in any method with an `unsafe` block. Beginning with C# 13, you can use `yield` in methods with `unsafe` blocks, but not in the `unsafe` block.
4141

4242
## Execution of an iterator
4343

docs/csharp/misc/cs1629.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,28 @@ f1_keywords:
66
- "CS1629"
77
helpviewer_keywords:
88
- "CS1629"
9-
ms.assetid: 907eae46-0265-4cd0-b27b-ff555d004259
109
---
1110
# Compiler Error CS1629
1211

13-
Unsafe code may not appear in iterators
12+
Unsafe code may not appear in iterators
1413

15-
This restriction is relaxed in C# 13. You can use `unsafe` blocks, but the `yield return` statement can't be used in an `unsafe` block.
16-
17-
The C# language specification does not allow unsafe code in iterators.
18-
19-
The following sample generates CS1629:
20-
21-
```csharp
22-
// CS1629.cs
14+
The C# language specification doesn't allow unsafe code in iterators. This restriction is relaxed in C# 13. You can use `unsafe` blocks, but the `yield return` statement can't be used in an `unsafe` block.
15+
16+
The following sample generates CS1629:
17+
18+
```csharp
19+
// CS1629.cs
2320
// compile with: /unsafe
24-
using System.Collections.Generic;
21+
using System.Collections.Generic;
2522
class C
26-
{
27-
IEnumerator<int> IteratorMeth() {
28-
int i;
29-
unsafe // CS1629
30-
{
31-
int *p = &i;
32-
yield return *p;
33-
}
34-
}
35-
}
23+
{
24+
IEnumerator<int> IteratorMeth() {
25+
int i;
26+
unsafe // CS1629
27+
{
28+
int *p = &i;
29+
yield return *p;
30+
}
31+
}
32+
}
3633
```

0 commit comments

Comments
 (0)