There are two uses of the 'using' keyword:
- as a using directive, which permits the use of types in a namespace. For example:
using System.Web
as a using statement, which is only possible for types that inherit from IDisposable
. This automatically calls the Dispose()
method on the object after the using statement goes out of scope, so you don't have to worry about automatically calling this method yourself, or calling Close()
on database connections, for example:
using(MySqlConnection connection = new MySqlConnection())
{
//..
}