Using..End Using Statement

As an alternative to directly invoking Dispose, you can take advantage of the Using..End Using statement. This code block automatically releases and removes from memory the object that it points to, invoking Dispose behind the scenes for you. The following code example shows how you can open a stream for writing a file ensuring that the stream will be released even if you do not explicitly close it:

image

Notice how you simply create an instance of the object via the Using keyword. The End Using statement causes Dispose to be invoked on the previously mentioned instance. The advantage of Using..End Using is also that the resource is automatically released in cases of unhandled exceptions, and this can be useful.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.116.43