I understand that any time I am instantiating a class that implements IDisposable, I should use the using
keyword in order to ensure that it's disposed of properly.
Like so:
using (SecureString s = new SecureString())
{
}
The above is easy for me to understand - I can use s
however I want within those brackets, but once I leave those brackets, I can no longer refer to s
. The scope is easy to see.
But what I don't understand is how it works when you use using
with no enclosing brackets.
private void Function()
{
// Some code here
using (SecureString s = new SecureString())
// more code here
}
You aren't required to use brackets at all... so... how do I know where I am able to use the object and where it gets disposed, if there are no brackets to go with the using
keyword?