Bird
0
0

What will the following C# code output?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - File IO
What will the following C# code output?
using System;
using System.IO;

class Program {
  static void Main() {
    File.WriteAllText("test.txt", "Hello World");
    string content = File.ReadAllText("test.txt");
    Console.WriteLine(content);
  }
}
AHello World
BEmpty line
CFile not found error
Dtest.txt
Step-by-Step Solution
Solution:
  1. Step 1: Write text to file

    File.WriteAllText creates or overwrites "test.txt" with "Hello World".
  2. Step 2: Read text from file and print

    File.ReadAllText reads the content back, which is "Hello World", then prints it.
  3. Final Answer:

    Hello World -> Option A
  4. Quick Check:

    WriteAllText + ReadAllText = same text output [OK]
Quick Trick: Write then read file outputs saved text [OK]
Common Mistakes:
MISTAKES
  • Expecting filename instead of file content
  • Thinking file is missing causing error
  • Assuming output is empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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