Skip to content

using declaration example doesn't understand variable scopes #21151

@jeffreycoxdoosan

Description

@jeffreycoxdoosan

This comment is incorrect:
// We must declare the variable outside of the using block
// so that it is in scope to be returned.

The example works just fine like this:

    using (var file = new System.IO.StreamWriter("WriteLines2.txt"))
    {
        int skippedLines = 0;
        foreach (string line in lines)

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions