Using Keyword
There are two purposes: Using and using. Where
The Using command has two purposes:
(1) The type can be used in the namespace, so that you do not have to limit the type used in the namespace.
(2) create an alias for the namespace.
Note: The range of the using command is limited to files containing it. Create a using alias to limit the identifier to a namespace or type. Create the using command to use the type in the namespace without specifying the namespace. The Using command does not provide users with access to any namespaces nested in the specified namespace.
Using statement:
Defines a range to release one or more objects out of this range.
The usage of the using command is very common. Here we will explain how the using statement releases objects. C # Use the. NET Framework Common Language Runtime Library (CLR) to automatically release the memory used to store unnecessary objects. The release of memory is uncertain. Once the CLR decides to execute garbage collection, the memory will be released. However, it is usually best to release limited resources such as file handles and network connections as soon as possible.
UsingThe statement allows the programmer to specify when the resource object should be released..
The object provided for the using statement must implement the idisposable interface.
This interface provides the dispose method, which releases the resources of this object.
The Using statement can be used with multiple objects at the same time,
Note that these objects must be declared inside the using statement..
Using (font fontone = new font ("", 10.0f), fonttwo = new font ("Arial", 8.0f ))
{
// You can use the fontone object and fonttwo object
}
// The fontone objects and fonttwo objects cannot be used any more because they are released.
The above is the simple usage of using.