What does the C# using statement guarantee for an object such as a StreamReader?
Correct answer A. Its Dispose method is called when the block is exited, even if an exception is thrown
The using statement works with types implementing IDisposable. The compiler expands it into try/finally and calls Dispose in the finally block, so files, sockets and database connections are released promptly even on an exception. Since C# 8 you can also write a using declaration, using var r = ...;, disposed at the end of the scope. The using directive for namespaces is a different feature.
Answer checked How we write and check questions
Discussion