When I was writing some I/O routine in C++, I would usually make it as generic as possible, by operating on the interfaces from <iostream>.
For example:
void someRoutine(std::istream& stream) { ... }
How should the same be done in C#?
I suspect I could write my routines based on the System.IO.TextReader or System.IO.TextWriter, but I’m not sure.
Obviously I’m seeking for a same base class in C#, which is as generic as std::istream or std::ostream and which can be extended in many ways (for example, as boost::iostreams extends the std:: streams).
If you want to work with strings, you should take a
TextReaderorTextWriter.If you want to work with bytes, you should take a
Stream.These classes are inherited by concrete implementations such as
FileStream,StringWriter, andNetworkStream.