Bird
0
0

Which of the following is the correct syntax to open a file for reading using StreamReader in C#?

easy📝 Syntax Q3 of 15
C Sharp (C#) - File IO
Which of the following is the correct syntax to open a file for reading using StreamReader in C#?
Avar reader = StreamReader.Read("file.txt");
Bvar reader = StreamReader.Open("file.txt");
Cvar reader = new FileReader("file.txt");
Dvar reader = new StreamReader("file.txt");
Step-by-Step Solution
Solution:
  1. Step 1: Recall StreamReader constructor usage

    StreamReader is instantiated with new and the file path as a string.
  2. Step 2: Check other options for correctness

    StreamReader.Open and StreamReader.Read do not exist; FileReader is not a C# class.
  3. Final Answer:

    var reader = new StreamReader("file.txt"); -> Option D
  4. Quick Check:

    StreamReader constructor uses new with file path [OK]
Quick Trick: Use 'new StreamReader("filename")' to open file for reading [OK]
Common Mistakes:
MISTAKES
  • Using non-existent methods like Open or Read
  • Confusing class names
  • Omitting new keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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