这是我的代码,不言自明。using
块终止后-output
正在处理变量。为什么?我想从函数中返回它,处理 StreamWriter 但返回我的对象的正确方法是什么?
public static Stream Write(Interchange interchange)
{
var output = new MemoryStream();
using (TextWriter writer = new StreamWriter(output))
{
foreach (var rawSegment in GetRawSegments(interchange))
{
writer.Write(rawSegment.ToString(interchange.ElementDelimeter, interchange.SegmentTerminator));
}
writer.Flush();
}
return output;
}