假设这个 C# 代码:
using (MemoryStream stream = new MemoryStream())
{
StreamWriter normalWriter = new StreamWriter(stream);
BinaryWriter binaryWriter = new BinaryWriter(stream);
foreach(...)
{
binaryWriter.Write(number);
normalWriter.WriteLine(name); //<~~ easier to reader afterward.
}
return MemoryStream.ToArray();
}
我的问题是:
- 我是否需要在循环内使用刷新来保持顺序?
- 回国
MemoryStream.ToArray()
合法吗?我使用using
-block 作为约定,我担心它会搞砸。