I am just looking at the using statement, I have always known what it does but until now not tried using it, I have come up with the below code:
using (SqlComma
one issue with "using" is that it doesn't handles exceptions. if the designers of "using" would add "catch" optionally to its syntax like below pseudocode, it would be much more useful:
using (...MyDisposableObj...)
{
... use MyDisposableObj ...
catch (exception)
... handle exception ...
}
it could even have an optional "finally" clause to cleanup anything other than the "MyDisposableObj" allocated at the beginning of the "using" statement... like:
using (...MyDisposableObj...)
{
... use MyDisposableObj ...
... open a file or db connection ...
catch (exception)
... handle exception ...
finally
... close the file or db connection ...
}
still there'll be no need to write code to dispose of MyDisposableObj b/c it'd be handled by using...
How do like that?