Possible Duplicate:
What is the C# Using block and why should I use it?
So I've just noticed that at msdn examples and some stackoverflow questions there were answer where the using statement is used before the streamwriter etc, but what is actually the benefit? Since I've never been taught/told/read any reason to use it.
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
Console.WriteLine(sr.ReadLine());
}
Instead of:
StreamReader sr = new StreamReader(path);
while (sr.Peek() >= 0)
Console.WriteLine(sr.ReadLine());