开发者

Difference Between StreamWriter/Reader and StringWriter/Readerll

Im very confused with the exact difference between them and different usage approach of these two TextWriter/Reader derived types StringWriter/Reader and StreamReader/Reader. I know that using them we can deal easily with character based开发者_JS百科 data in stream avoiding byte fuss as working direclty using Filestream...


  • TextWriter/Reader is an abstract class. It provides an abstraction for writing/reading character based data to/from a data source.

  • StreamWriter/Reader is a concrete implementation that uses a writeable/readable Stream as data source. Since a Stream is abstraction for writing/reading byte based data, an Encoding instance is required for the translation between characters and bytes.

  • StringWriter/Reader is a concrete implementation that uses a StringBuilder/string as data source.


The Stream* classes read from a Stream.
The String* classes read from a String (and write to a StringBuilder).

You can write a method that takes a TextReader, and call it with a StreamReader or a StringReader for it to read from a stream or a string.


here you have the difference

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/9e86374b-bdab-4d33-b0de-e72f8f7e913e

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜