What's the point of StringWriter?

  • Thread starter Thread starter Chris-
  • Start date Start date
C

Chris-

Putting aside the fact XmlTextReader and various ASP.NET classes use
StringWriter, what purpose is it meant to serve?

All it does is use the provided StringBuilder and .Append() to it from
what I can tell while implementing IDisposable. Can someone shed some
light?
 
Chris- said:
Putting aside the fact XmlTextReader and various ASP.NET classes use
StringWriter, what purpose is it meant to serve?

All it does is use the provided StringBuilder and .Append() to it from
what I can tell while implementing IDisposable. Can someone shed some
light?

Any time you need to provide a TextWriter and you want to keep the data
in memory, StringWriter is ideal. Think of it as the write-only text
equivalent of a MemoryStream.
 
Overall, it is just an encapsulation to make things easier, as it works with
the same basic model as the other writers and readers, which reduces the
need to change your patterns when you using an in memory string
representation output to standard out instead of terminating at a more
persistent medium, like a text file.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
Back
Top