473,379 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 16181
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
I created a StreamReader object from a local file on my c:\ drive StreamReader srTemp = new StreamReader("C:\\myFile.txt") I then used a RegEx to strip out all the html and save what's left to...
6
by: Jesper | last post by:
Hi, Im using a code snippet that reads a text file from disc and processes it using stream = new StreamReader(filename); Is it possible to assign a String instead of a file as the source of...
1
by: AMP | last post by:
Hello, I am trying to see if a FileStream Opened using an"if" clause: FileStream infile = new FileStream("c:\\blink2.txt", FileMode.Open, FileAccess.Read, FileShare.Read); if (infile==0)..... ...
11
by: info | last post by:
Hi All, How can i rewind the following sile stream: TextReader tr = new StreamReader(File.Open(fileName, FileMode.Open)); Is there a dedicated method or shall I close and re-open the...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
3
by: trint | last post by:
When testing locally with: TextReader tr = new StreamReader(@"C:\gcc.set"); Now that I have uploaded this to the server on the net, that locations permissions are denied. How can I change this to...
1
by: Rene | last post by:
Hi, I decided to take a closer look at the TextWriter and TextReader abstract classes just for fun. While poking around, I noticed that the TextWriter class includes an 'Encoding' property in...
3
by: =?Utf-8?B?Qm9zc2ll?= | last post by:
Hi All, I am having a little trouble with a StreamReader. I am currently reading a pipe delimited file with around 1.8 million records (total size 150MB) and, based on a flag, insert update or...
3
by: Tony Johansson | last post by:
Hello! I just wonder in this specific case is it any advantage to use a TextReader a reference to a StreamReader ? Try { TextReader tr = new StreamReader(locationTextBox.Text); Try {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.