Skip to content

Commit 2a98410

Browse files
authored
Fix error in using statement scopes (#21161)
Fixes #21151 The return can be inside the using scope, so the description of the existing feature was incorrect.
1 parent a5e5037 commit 2a98410

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

docs/csharp/whats-new/csharp-8.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ A **using declaration** is a variable declaration preceded by the `using` keywor
265265
static int WriteLinesToFile(IEnumerable<string> lines)
266266
{
267267
using var file = new System.IO.StreamWriter("WriteLines2.txt");
268-
// Notice how we declare skippedLines after the using statement.
269268
int skippedLines = 0;
270269
foreach (string line in lines)
271270
{
@@ -289,11 +288,9 @@ In the preceding example, the file is disposed when the closing brace for the me
289288
```csharp
290289
static int WriteLinesToFile(IEnumerable<string> lines)
291290
{
292-
// We must declare the variable outside of the using block
293-
// so that it is in scope to be returned.
294-
int skippedLines = 0;
295291
using (var file = new System.IO.StreamWriter("WriteLines2.txt"))
296292
{
293+
int skippedLines = 0;
297294
foreach (string line in lines)
298295
{
299296
if (!line.Contains("Second"))

0 commit comments

Comments
 (0)