Will a using statement rollback a database transaction if an error occurs?

Dispose method for transaction class performs a rollback while Oracle’s class doesn’t. So from transaction’s perspective it’s implementation dependent. The using statement for the connection object on the other hand would either close the connection to the database or return the connection to the pool after resetting it. In either case, the outstanding transactions should … Read more

Does Dispose still get called when exception is thrown inside of a using statement?

Yes, using wraps your code in a try/finally block where the finally portion will call Dispose() if it exists. It won’t, however, call Close() directly as it only checks for the IDisposable interface being implemented and hence the Dispose() method. See also: Intercepting an exception inside IDisposable.Dispose What is the proper way to ensure a … Read more

How to use an iterator?

That your code compiles at all is probably because you have a using namespace std somewhere. (Otherwise vector would have to be std::vector.) That’s something I would advise against and you have just provided a good case why: By accident, your call picks up std::distance(), which takes two iterators and calculates the distance between them. … Read more

What is the C# Using block and why should I use it? [duplicate]

If the type implements IDisposable, it automatically disposes that type. Given: public class SomeDisposableType : IDisposable { …implmentation details… } These are equivalent: SomeDisposableType t = new SomeDisposableType(); try { OperateOnType(t); } finally { if (t != null) { ((IDisposable)t).Dispose(); } } using (SomeDisposableType u = new SomeDisposableType()) { OperateOnType(u); } The second is easier … Read more