Reprinted from: http://www.cnblogs.com/heyaowen163/articles/1177909.html
(1) reference a namespace
The usage rules of using as a namespace instruction are as follows:
Using Namespace;
In. NET programs, the most common code is to introduce the System namespace at the beginning of the program file, the reason is that the System namespace encapsulates many of the most basic and most commonly used operations, the following code is most familiar to us:
Using System;
In this way, we can directly use the type in the namespace in the program without specifying the detailed type name. The using command can access the nested namespace.
About: namespace
The namespace is. the logical structure of the NET program, rather than the actual physical structure, is a way to avoid class name conflicts, used to divide different data types. For example, in. NET, many basic types are in the System namespace, and the Data operation type is in the System. Data namespace,
(2) create a namespace alias
The usage rules for using to create an alias for a namespace are as follows:
Using alias = namespace | type;
Namespace indicates the alias used to create a namespace, and type indicates the alias used to create a namespace. For example.. NET Office applications, Microsoft. office. interop. word. dll assembly. To avoid tedious type input when introducing namespaces, we usually create aliases for them as follows:
Using MSWord = Microsoft. Office. Interop. Word;
In this way, Microsoft. Office. Interop. Word prefix can be replaced by MSWord in the program. If you want to create an Application object, this can be the case,
Another benefit is that when different namespaces but the same class names are introduced in a. CS file, aliases can be used to solve this problem.
(3) force resource cleaning
Purpose: Clear unmanaged resources that are not controlled by GC. After the Using ends, the Disposable method is called implicitly.
Usage:
Using (Class1 c = new Class1 ())
{
} // Clear unmanaged resources not controlled by GC
However, when an object uses the using Keyword, The IDisposable interface must be implemented. In fact, using works the same way as calling the Disposable method in the finaly code field in try-catch-finaly. Note that Using cannot use multiple different classes.
Code
Class1 f = new Class1 ();
Try
{
// Execute the code
}
Catch ()
{
// Exception Handling
}
Finally
{
F. Disposable ();
}