470,594 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

StreamReader, StringReader, TextReader

StreamReader says it is designed to read a stream of characters
StringReader says it is designed to read a string
TextReader says it is designed to read a sequential list of characters.

I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's
the difference?

--
TFWBWY...A
Nov 21 '05 #1
2 15662
The difference is in the source of the characters. The Stream reader
gets its data from a stream. This could be a memory stream, a file
stream, a stream from a serial port. A stream might come from a video
capture device. It provides a consistent methodology for reading data,
regardless of the source. The StringReader reads data from another
string. The TextReader reads data from a text file.

Nov 21 '05 #2
Bryan,
In addition to the other comments:

Short answer: Its called Inheritance! Remember Inheritance is one of the
major tenants of OO.

StreamReader inherits from TextReader
StringReader inherits from TextReader

In other words: both StreamReader & StringReader are types of TextReaders.
Long answer:

TextReader has all the common logic on reading characters, it declares the
"contract" on how to read characters. StreamReader has the specifics on
reading characters from a Stream (aka a File) it fills in the specific of
the "contract" to read characters from a Stream. While StringReader has the
specifics on reading characters from a String (for example the clipboard or
a TextBox) it fills in the specifics of the "contract" to read characters
from a String.
If I am writing a routine that needs to read Text, generally I will write it
based on a TextReader. This way I can pass it either a StreamReader or a
StringReader & the routine itself is non the wiser. Additionally if a new
type of TextReader is defined, my routine will be able to handle it also...

Hope this helps
Jay

"Bryan Dickerson" <tx******@netscape.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
| StreamReader says it is designed to read a stream of characters
| StringReader says it is designed to read a string
| TextReader says it is designed to read a sequential list of characters.
|
| I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's
| the difference?
|
| --
| TFWBWY...A
|
|
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jesper | last post: by
3 posts views Thread by trint | last post: by
3 posts views Thread by =?Utf-8?B?Qm9zc2ll?= | last post: by
3 posts views Thread by Tony Johansson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.