嗨,为什么 using (var sw = new StreamWriter(ms))
返回 Cannot access a closed Stream
exception
。 Memory Stream
在这段代码之上。
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms))
{
sw.WriteLine("data");
sw.WriteLine("data 2");
ms.Position = 0;
using (var sr = new StreamReader(ms))
{
Console.WriteLine(sr.ReadToEnd());
}
} //error here
}
最好的解决办法是什么? 谢谢