Bird
0
0

What is the issue with the following C# code that attempts to read all lines from "log.txt"?

medium📝 Debug Q6 of 15
C Sharp (C#) - File IO
What is the issue with the following C# code that attempts to read all lines from "log.txt"?
var lines = File.ReadAllLines("log.txt";
AMissing closing parenthesis in the method call
BUsing var instead of string[] for lines
CFile.ReadAllLines cannot read .txt files
DThe file path should be an absolute path
Step-by-Step Solution
Solution:
  1. Step 1: Check method syntax

    The method call File.ReadAllLines("log.txt"; is missing a closing parenthesis.
  2. Step 2: Validate variable type

    Using var is valid here because the method returns a string array.
  3. Step 3: Confirm file type support

    File.ReadAllLines supports reading text files including .txt files.
  4. Final Answer:

    Missing closing parenthesis in the method call -> Option A
  5. Quick Check:

    Check parentheses balance [OK]
Quick Trick: Always check for balanced parentheses [OK]
Common Mistakes:
MISTAKES
  • Forgetting closing parentheses in method calls
  • Assuming var cannot be used for arrays
  • Thinking File.ReadAllLines only reads absolute paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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