Sometimes, you have to create two Disposable
objects in a row. There is an easy way to avoid nesting Using
blocks.
This code
Using File As New FileStream("MyFile", FileMode.Append)
Using Writer As New BinaryWriter(File)
'You code here
Writer.Writer("Hello")
End Using
End Using
can be shortened into this one. The main advantage is that you gain one indentation level:
Using File As New FileStream("MyFile", FileMode.Append), Writer As New BinaryWriter(File)
'You code here
Writer.Writer("Hello")
End Using