Bird
0
0

What will be the content of the file "notes.txt" after running this code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - File IO
What will be the content of the file "notes.txt" after running this code?
string path = "notes.txt";
File.WriteAllText(path, "Line 1\nLine 2");
File.WriteAllText(path, "New Line");
ANew Line
BLine 1\nLine 2
CEmpty file
DLine 1\nLine 2\nNew Line
Step-by-Step Solution
Solution:
  1. Step 1: Analyze first File.WriteAllText call

    The first call writes "Line 1\nLine 2" to "notes.txt", creating or overwriting the file.
  2. Step 2: Analyze second File.WriteAllText call

    The second call overwrites the entire file content with "New Line", replacing previous text.
  3. Final Answer:

    New Line -> Option A
  4. Quick Check:

    Second WriteAllText overwrites file content [OK]
Quick Trick: WriteAllText overwrites file, last call wins [OK]
Common Mistakes:
MISTAKES
  • Assuming text appends instead of overwriting
  • Thinking both texts combine in file
  • Ignoring the second WriteAllText call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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