Bird
0
0

What does the File.ReadAllLines method do in C#?

easy🧠 Conceptual Q11 of 15
C Sharp (C#) - File IO
What does the File.ReadAllLines method do in C#?
AReads the entire file content as a single string.
BReads all lines from a text file and returns them as a string array.
CWrites lines to a text file.
DDeletes the specified text file.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the method purpose

    File.ReadAllLines reads a text file and returns each line as an element in a string array.
  2. Step 2: Compare with other methods

    File.ReadAllText returns the whole file as one string, not an array of lines.
  3. Final Answer:

    Reads all lines from a text file and returns them as a string array. -> Option B
  4. Quick Check:

    ReadAllLines = string array [OK]
Quick Trick: ReadAllLines returns array of lines, not one big string [OK]
Common Mistakes:
MISTAKES
  • Confusing ReadAllLines with ReadAllText
  • Thinking it writes to a file
  • Assuming it deletes files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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