How to capture stream data? C# I/O Basic
I need to use a method which accepts two arguments Model type and Stream Type.
public static void W开发者_StackOverflow中文版rite(Stream stream, Model model);
Firstly i want to create a variable of type stream and then capture what ever is written to the stream in a string and then store in database. I find that Stream class is a abstract class not sure how to override it.
Can any one please suggest ?
You could use some of the derived classes such as MemoryStream:
using (var stream = new MemoryStream())
{
// pass the memory stream to the method which will write to it
SomeClass.Write(stream, someModel);
// convert the contents to string using the default encoding
string result = Encoding.Default.GetString(stream.ToArray());
// TODO: do something with the result
}
精彩评论