Bird
0
0

Which of the following is the correct syntax to read all text from a file named "data.txt" using File.ReadAllText?

easy📝 Syntax Q12 of 15
C Sharp (C#) - File IO
Which of the following is the correct syntax to read all text from a file named "data.txt" using File.ReadAllText?
Astring content = File.ReadAllText("data.txt");
Bstring content = File.ReadAllLines("data.txt");
Cstring[] content = File.ReadAllText("data.txt");
Dstring[] content = File.ReadAllLines("data.txt");
Step-by-Step Solution
Solution:
  1. Step 1: Identify method return types

    File.ReadAllText returns a single string, so the variable must be string.
  2. Step 2: Match syntax with variable type

    string content = File.ReadAllText("data.txt"); uses string variable with ReadAllText correctly. Options B and D mismatch method and variable types. string[] content = File.ReadAllText("data.txt"); tries to assign string to string array.
  3. Final Answer:

    string content = File.ReadAllText("data.txt"); -> Option A
  4. Quick Check:

    ReadAllText returns string, so variable is string [OK]
Quick Trick: Match method return type with variable type [OK]
Common Mistakes:
MISTAKES
  • Assigning ReadAllText to string array
  • Using ReadAllLines but expecting string
  • Wrong variable type for method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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