C Sharp (C#) - File IOWhich 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");Check Answer
Step-by-Step SolutionSolution:Step 1: Recall StreamReader constructor usageStreamReader is instantiated with new and the file path as a string.Step 2: Check other options for correctnessStreamReader.Open and StreamReader.Read do not exist; FileReader is not a C# class.Final Answer:var reader = new StreamReader("file.txt"); -> Option DQuick Check:StreamReader constructor uses new with file path [OK]Quick Trick: Use 'new StreamReader("filename")' to open file for reading [OK]Common Mistakes:MISTAKESUsing non-existent methods like Open or ReadConfusing class namesOmitting new keyword
Master "File IO" in C Sharp (C#)9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More C Sharp (C#) Quizzes Collections - LinkedList usage - Quiz 1easy Collections - Collection initialization syntax - Quiz 8hard Interfaces - Default interface methods - Quiz 6medium LINQ Fundamentals - LINQ method syntax - Quiz 5medium LINQ Fundamentals - Why LINQ is needed - Quiz 10hard LINQ Fundamentals - First, Single, and their OrDefault variants - Quiz 13medium Polymorphism and Abstract Classes - When to use abstract vs concrete - Quiz 11easy Properties and Encapsulation - Computed properties - Quiz 15hard Strings and StringBuilder - Verbatim and raw string literals - Quiz 9hard Strings and StringBuilder - StringBuilder methods and performance - Quiz 6medium