Multiple choice .net

Which method is found in both the StreamReader and StreamWriter class?

  1. Close

  2. Peak

  3. Flush

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to have a basic understanding of the StreamReader and StreamWriter classes in .NET.

Option A: Close - This method is found in both the StreamReader and StreamWriter classes. It is used to close the underlying stream and free up any resources associated with it.

Option B: Peek - This method is not found in both the StreamReader and StreamWriter classes. It is only found in the StreamReader class and is used to return the next available character without reading it from the underlying stream.

Option C: Flush - This method is found in both the StreamReader and StreamWriter classes. It is used to flush the buffer and write any remaining data to the underlying stream.

Option D: Both A and B - This option is incorrect because option B is not found in both the StreamReader and StreamWriter classes.

Option E: All of the above - This option is incorrect because option B is not found in both the StreamReader and StreamWriter classes.

Therefore, the correct answer is:

The Answer is: A. Close.

AI explanation

Close is the method present on both StreamReader and StreamWriter (via their common ancestry through TextReader/TextWriter and the underlying Stream), since both need to release the file handle/resources when done. Flush, however, is meaningful only for output — it forces buffered writes out to the underlying stream — so it exists on StreamWriter (and TextWriter) but not on StreamReader, which has nothing to 'flush' since it only reads. 'Peak' isn't a real method name (Peek exists on TextReader, not TextWriter). So Close is the one method genuinely shared by both classes.