Bird
Raised Fist0

Find the problem in this code:

medium📝 Debug Q7 of Q15
C Sharp (C#) - File IO
Find the problem in this code:
using var writer = new StreamWriter("output.txt");
writer.WriteLine("Test");
// Missing closing brace or block
ANo problem; using var disposes automatically at scope end.
BMissing braces cause compilation error.
CStreamWriter must be disposed manually.
DWriteLine cannot be called outside using block.
Step-by-Step Solution
Solution:
  1. Step 1: Understand using var syntax

    Using var declares a disposable variable disposed at the end of the scope automatically.
  2. Step 2: Check if braces are mandatory

    Braces are optional with using var; no compilation error occurs.
  3. Final Answer:

    No problem; using var disposes automatically at scope end. -> Option A
  4. Quick Check:

    using var = automatic disposal without braces [OK]
Quick Trick: using var disposes at scope end without braces [OK]
Common Mistakes:
MISTAKES
  • Thinking braces are required with using var
  • Believing manual disposal is needed
  • Assuming WriteLine must be inside braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes