Bird
0
0

Find the problem in this code:

medium📝 Debug Q7 of 15
C Sharp (C#) - File IO
Find the problem in this code:
using(var writer = new StreamWriter("log.txt")) {
    writer.WriteLine("Start");
}
writer.WriteLine("End");
AStreamWriter cannot write strings
BWriteLine() cannot be called twice
CFile path must be absolute
Dwriter is used outside its using block causing error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze using block scope

    writer is declared inside using block and disposed after block ends.
  2. Step 2: Check usage after disposal

    Calling writer.WriteLine outside the block causes an error because writer is disposed.
  3. Final Answer:

    writer is used outside its using block causing error -> Option D
  4. Quick Check:

    Using block disposes writer after block ends [OK]
Quick Trick: Use StreamWriter only inside using block scope [OK]
Common Mistakes:
MISTAKES
  • Using disposed StreamWriter
  • Thinking WriteLine() usage is limited
  • Assuming relative paths cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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