Bird
0
0

Which of the following is the correct syntax to open a file for writing using StreamWriter in C#?

easy📝 Syntax Q12 of 15
C Sharp (C#) - File IO
Which of the following is the correct syntax to open a file for writing using StreamWriter in C#?
AStreamWriter writer = StreamWriter("file.txt");
Busing (StreamWriter writer = new StreamWriter("file.txt")) { }
Cusing StreamWriter writer = new StreamWriter("file.txt");
DStreamWriter writer = new StreamWriter.read("file.txt");
Step-by-Step Solution
Solution:
  1. Step 1: Recognize correct StreamWriter instantiation

    The correct way is to use new StreamWriter("file.txt") inside a using block for safe disposal.
  2. Step 2: Check syntax correctness

    using (StreamWriter writer = new StreamWriter("file.txt")) { } uses using with proper syntax and constructor call.
  3. Final Answer:

    using (StreamWriter writer = new StreamWriter("file.txt")) { } -> Option B
  4. Quick Check:

    Correct StreamWriter syntax = B [OK]
Quick Trick: Use 'using' with new StreamWriter(filename) [OK]
Common Mistakes:
MISTAKES
  • Missing 'new' keyword
  • Not using 'using' block for disposal
  • Incorrect method calls like .read() on StreamWriter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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