C Sharp (C#) - Exception Handling
Which of the following correctly demonstrates the use of a
using statement to manage a disposable resource in C#?using statement to manage a disposable resource in C#?using statement requires parentheses around the resource declaration and a block of code.using (var resource = new Resource()) { ... }. using var resource = new Resource(); resource.DoWork(); is valid syntax in C# 8.0 and later, so it is also correct. using Resource resource = new Resource(); resource.DoWork(); omits parentheses and uses incorrect syntax. using (Resource resource = new Resource()) resource.DoWork(); lacks braces which is allowed only if the statement is a single line, but the resource declaration must be inside parentheses.using requires parentheses and braces [OK]15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions