Confused About ‘using’ statement.

Would someone please explain to me why this code works: using (StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts"))) w.WriteLine("123.123.123.123 FQDN");

But this code doesn't?: StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts")); w.WriteLine("123.123.123.123 FQDN");

Thanks!

by throughdeadlywaters2 via /r/csharp

Leave a Reply