Back to questions
JuniorTheoryCommon
What does the program print?
Show();
Console.Write("C");
void Show()
{
using var light = new Light();
Console.Write("A");
}
class Light : IDisposable
{
public void Dispose() => Console.Write("B");
}ABC
- Expecting
BAC: ausing vardeclaration callsDisposeat the end of its enclosing block, not right after the line that declares it. - Expecting
Disposeto run only at the end of the program, or never:usingcalls it as soon as the block is left.
- What would the program print if
Showthrew an exception after writingAand the caller caught it? - What does the compiler turn a
usingdeclaration into?