【发布时间】:2011-09-03 22:10:18
【问题描述】:
现在我正在使用 XmlTextWriter 将 MemoryStream 对象转换为字符串。但我不知道是否有更快的方法将内存流序列化为字符串。
我按照此处给出的代码进行序列化 - http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp
已编辑
流到字符串
ms.Position = 0;
using (StreamReader sr = new StreamReader(ms))
{
string content = sr.ReadToEnd();
SaveInDB(ms);
}
串流
string content = GetFromContentDB();
byte[] byteArray = Encoding.ASCII.GetBytes(content);
MemoryStream ms = new MemoryStream(byteArray);
byte[] outBuf = ms.GetBuffer(); //error here
【问题讨论】:
标签: c# xml-serialization memorystream