Bird
Raised Fist0

Which of the following is the correct way to write the string "Welcome" to a file named "message.txt" using File.WriteAllText in C#?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - File IO
Which of the following is the correct way to write the string "Welcome" to a file named "message.txt" using File.WriteAllText in C#?
AFile.WriteAllText("message.txt");
BFile.WriteAllText("Welcome", "message.txt");
CFile.WriteAllText(message.txt, Welcome);
DFile.WriteAllText("message.txt", "Welcome");
Step-by-Step Solution
Solution:
  1. Step 1: Understand the method signature

    File.WriteAllText takes two parameters: the file path and the content string.
  2. Step 2: Identify correct parameter order

    The first argument should be the file name as a string, the second the text to write.
  3. Final Answer:

    File.WriteAllText("message.txt", "Welcome"); -> Option D
  4. Quick Check:

    Correct parameter order and types used [OK]
Quick Trick: File.WriteAllText(path, content) writes text to file [OK]
Common Mistakes:
MISTAKES
  • Swapping the order of parameters
  • Omitting the content parameter
  • Not using quotes around strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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