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.
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.