有时,您必须Disposable连续创建两个对象。有一个避免嵌套Using块的简单方法。
这段代码
Using File As New FileStream("MyFile", FileMode.Append) Using Writer As New BinaryWriter(File) 'You code here Writer.Writer("Hello") End Using End Using
可以简化为这个。主要优点是您获得了一个缩进级别:
Using File As New FileStream("MyFile", FileMode.Append), Writer As New BinaryWriter(File) 'You code here Writer.Writer("Hello") End Using