by bruceboughton · 12y ago · 0 comments
using (var file2 = new StreamReader(file))
{
while ((line = file2.ReadLine()) != null)
Console.WriteLine(line);
}
It's possible this is a badly picked example but it shows one big downside of this -- the lack of discussion about the sample code that you would normally get at e.g. Stack Overflow or a blog.The easy solution is to make sure that your Dispose() calls don't throw exceptions, unfortunately some of Microsoft's classes don't conform to this (e.g. WCF clients).
The following MSDN article shows a case where they do not recommend using "using", and instead suggest explicitly using try-catch-finally: http://msdn.microsoft.com/en-us/library/aa355056.aspx
[Citation needed]
Then what's the point of having a 'using + catch' instead of a 'try catch finally' ?