473,320 Members | 2,020 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,320 software developers and data experts.

What is the difference between TextWriter and StreamWriter ?

Some sample source codes use TextWriter other StreamWriter for writing text into a file.

What are the differences ?

Carla

May 24 '07 #1
2 16425
"Carla Simeoni" <c.****@subnet.netwrote in message
news:46***********************@newsspool3.arcor-online.net...
Some sample source codes use TextWriter other StreamWriter for writing
text into a file.

What are the differences ?
StreamWriter inherits from TextWriter. That is, every StreamWriter IS A
TextWriter.
TextWriter is an abstract class, so you can't create an instance of a
TextWriter. You always have to do a "new" of a child class (such as
StreamWriter or StringWriter), which you can then assign to a TextWriter
variable.

May 24 '07 #2
On Thu, 24 May 2007 13:18:54 -0700, Carla Simeoni <c.****@subnet.net>
wrote:
Some sample source codes use TextWriter other StreamWriter for writing
text into a file.

What are the differences ?
In addition to what Alberto said, one reason you may see both is that
there may be code that wants to be able to support any TextWriter (two
common ones being the built-in StreamWriter and StringWriter). That way
you have use the same code to write, for example, your text to a file or a
string.

In fact, this sort of thing is one of the big reasons we have virtual
functions and interfaces. The ability to declare some basic API common to
a wide variety of object, each with their own custom implementation. :)

Pete
May 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: marcstober | last post by:
Hi -- I'm trying to write a class that will work like a StreamWriter, but will direct output into two different places, such as a GUI along with either a text file or database table. My first...
11
by: D | last post by:
I have a winforms app that I'm reading some records from a datareader and writing them out to a file like so SqlDataReader dataReader = sqlCommand.ExecuteReader(); TextWriter textWriter = new...
3
by: fniles | last post by:
Is this the correct syntax to make a Textwriter thread safe ? Thank you. Dim swError As TextWriter Dim swErrorSync As TextWriter swError = New StreamWriter(Application.StartupPath & "\Log.txt",...
54
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor,...
1
by: jtertin | last post by:
I am currently using the following code to make sure a file is writable (i.e. is not in use) by using the CanWrite method of the FileStream object. Using the code below, the TextWriter is still...
2
by: kengtung | last post by:
Greetings all, I just started programming with C# (.Net FW 1.1) last year and still learning. Previously I am using VB 6.0. Recently, in one application, I encountered a C# error "Cannot write...
6
by: John | last post by:
Hi What is the difference between System.IO.TextWriter vs System.IO.TextWriter? Thanks Regards
2
by: raylopez99 | last post by:
I can't get the below code to work, no matter how many times I change it. I do have the Image file, Image1, created (in another method), and using "hard coding" I can save it (it's a filled...
0
by: rajeshreddye | last post by:
In my multi-threaded application i'm getting to a point where I've got the exception bellow: Data Extraction failed due to the following exception ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.