Using statement
using System;
using System.IO;
class Program
{
static void Main()
{
// Using statement to ensure the StreamReader is disposed of properly
using (StreamReader reader = new StreamReader("example.txt"))
{
string content = reader.ReadToEnd();
Console.WriteLine(content);
} // reader.Dispose() is called automatically here
}
}Last updated