Bird
0
0

Why might File.ReadAllLines throw an exception when reading a large file?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - File IO
Why might File.ReadAllLines throw an exception when reading a large file?
AIt requires a StreamReader instance to work
BIt loads entire file into memory, causing OutOfMemoryException
CIt only reads the first line and ignores the rest
DIt automatically deletes the file after reading
Step-by-Step Solution
Solution:
  1. Step 1: Understand ReadAllLines behavior

    ReadAllLines loads all lines into a string array in memory at once.
  2. Step 2: Consider large file impact

    For very large files, this can exhaust memory and cause OutOfMemoryException.
  3. Step 3: Evaluate other options

    It reads all lines, does not need StreamReader instance, and does not delete files.
  4. Final Answer:

    It loads entire file into memory, causing OutOfMemoryException -> Option B
  5. Quick Check:

    Large file + ReadAllLines = memory risk [OK]
Quick Trick: ReadAllLines loads whole file in memory; large files risk errors [OK]
Common Mistakes:
MISTAKES
  • Thinking it reads line by line
  • Believing it needs StreamReader
  • Assuming it deletes files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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