Bird
0
0

What will be the content of "log.txt" after this code runs?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - File IO
What will be the content of "log.txt" after this code runs?
string log = "Start";
File.WriteAllText("log.txt", log);
File.AppendAllText("log.txt", " - End");
A - End
BStart
CStart\n - End
DStart - End
Step-by-Step Solution
Solution:
  1. Step 1: Write initial content

    File.WriteAllText writes "Start" to "log.txt".
  2. Step 2: Append text

    File.AppendAllText adds " - End" to existing content.
  3. Final Answer:

    File content is "Start - End". -> Option D
  4. Quick Check:

    AppendAllText adds text = Start - End [OK]
Quick Trick: Use AppendAllText to add without overwriting [OK]
Common Mistakes:
MISTAKES
  • Confusing AppendAllText with WriteAllText
  • Expecting newline added automatically
  • Thinking append replaces content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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