Bird
0
0

Which of the following is the correct syntax to write "Hello World" to a file named "greeting.txt" using File.WriteAllText?

easy📝 Syntax Q12 of 15
C Sharp (C#) - File IO
Which of the following is the correct syntax to write "Hello World" to a file named "greeting.txt" using File.WriteAllText?
AFile.WriteText("greeting.txt", "Hello World");
BFile.WriteAllText("Hello World", "greeting.txt");
CWriteAllText.File("greeting.txt", "Hello World");
DFile.WriteAllText("greeting.txt", "Hello World");
Step-by-Step Solution
Solution:
  1. Step 1: Check method name and parameters

    The correct method is File.WriteAllText with the first parameter as the file path and the second as the text content.
  2. Step 2: Validate syntax correctness

    File.WriteAllText("greeting.txt", "Hello World"); matches the correct method name and parameter order. Options A, B, and D have incorrect method names or parameter order.
  3. Final Answer:

    File.WriteAllText("greeting.txt", "Hello World"); -> Option D
  4. Quick Check:

    Correct method and parameter order = File.WriteAllText("greeting.txt", "Hello World"); [OK]
Quick Trick: Method name is File.WriteAllText(path, content) [OK]
Common Mistakes:
MISTAKES
  • Swapping parameters order
  • Using incorrect method names like WriteText
  • Calling method on WriteAllText instead of File

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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