What is the purpose of StreamReader when Stream.Read() exists?

前端 未结 3 1091
悲&欢浪女
悲&欢浪女 2020-12-15 23:48

This has been bugging me. I know Stream is an abstract class and therefore can\'t be instantiated but it has classes that are derived from it. Why is there

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 00:14

    TextReader (which StreamReader is derived from) works with strings. Stream works with bytes. The conversion between text and bytes is performed by an Encoding.

    Choose the right class based on whether the contents of your file text or binary.

    It is important to understand the difference between text and bytes.

提交回复
热议问题