When I use a using clause on an object should I dispose this object before exiting the using block?
using (var transaction = TransactionUtils.CreateTransactionScope())
{
try
{
_entity.Save(entity);
transaction.Complete();
}
catch // or better finally
{
transaction.Dispose(); // Is this try-catch usefull?
throw;
}
}
Note : A similar question has already been asked but I find the example and the answers strange.
It is redundant to dispose the object.
is equivalent to
For non-nullable value types the null-check is omitted and
dynamicis handled slightly different, too. See 8.13 in the C# Language Specification for more details.