I recently read that in
What is the possible use of StringWriter and StringReader, which cannot be done by StringBuilder itself?
StringWriter derive from
TextWriter respectively. So what they can do act as a
TextWriter instance, which
StringBuilder cannot because they do not derive either of those types.
What is the practical use of them?
They allow you to call APIs that are expecting a
TextWriter, when what you have/want is a
What could be the possible reason they are not taking up Stream as the input (Because any other writer and reader are taking the stream as the Constructor parameter to operate on) but the StringBuilder?
Because they don't work on streams; they work on
StringBuilders. They're just simple wrapper classes that adapt these types for APIs expecting a different interface. See: adapter pattern.