Bird
0
0

What will the following code print?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - File IO
What will the following code print?
using(var writer = new StreamWriter("data.txt")) {
    writer.Write("123");
    writer.Write("456");
}
using(var reader = new StreamReader("data.txt")) {
    string content = reader.ReadToEnd();
    Console.WriteLine(content);
}
A123 456
B123456
C123\n456
DError at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Write strings without newline

    Write() writes text without adding newlines, so "123" and "456" are concatenated.
  2. Step 2: Read entire content

    ReadToEnd() reads all text as one string, so output is "123456".
  3. Final Answer:

    123456 -> Option B
  4. Quick Check:

    Write() no newline; ReadToEnd() full text [OK]
Quick Trick: Write() appends text without newline [OK]
Common Mistakes:
MISTAKES
  • Expecting spaces or newlines between writes
  • Confusing Write() with WriteLine()
  • Assuming runtime error due to file access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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