I\'ve always used using with variable and assignment. Now i have like this a class DbProviderConnection:
public class DbProviderConnection : IDisposable
{
From the specification:
8.13 The using statement
A using statement of the form
using (ResourceType resource = expression) statement
when ResourceType is a nullable value type or a reference type other than dynamic, the expansion is
{
ResourceType resource = expression;
try {
statement;
}
finally {
if (resource != null) ((IDisposable)resource).Dispose();
}
}
A using statement of the form
using (expression) statement
has the same three possible expansions...The resource variable is inaccessible in, and invisible to, the embedded statement.
Therefore the object returned from cnctn.BeginTransaction()
will be disposed when the block exits, but is not accessible inside the associated block.