using Statement

A statement that disposes a resource automatically when execution leaves its scope.

What does using Statement do in C#?

using Statement — A statement that disposes a resource automatically when execution leaves its scope.

class OrderFile
{
    string Read(string path)
    {
        using StreamReader reader = new(path);
        return reader.ReadToEnd();
    }
}

Level: Journeyman · More C# terms at this level

Updated