Before we continue to FileInfo and Streams we need to explain using keyword in details.

Using directive

Using directive shortens our syntax so that we do not always have to type entire namespace:

Using directive grants us access to static members having to qualify the access with the type name:

Using directive enables us to create alias directive.

Using statement

Using statement provides us with a easy to use syntax which in return guarantees us with that types that implement IDisposable interface will be disposed of when we finish with them. For now do not stress yourself with questions like why do I need to dispose of something and what use IDisposable interface is to me. Those questions will be covered in a future post.

Example of using statement

Usage of using statement is straight-forward.

First we type using keyword and open parentheses, and inside of those brackets we instantiate class that implements IDisposable interface.  After that we proceed to use class instance inside curly brackets.

Of-course  you can instantiate more than one class while using using directive, just remember to separate them with coma:

I hope you will find using keyword helpful. I certainly use it on a daily basis in both forms