Using usage in C #
I wrote an example about how to use wcf. There is a using () {} sentence in it. In the past, using not only references namespaces, but also has other functions.
The using keyword is used in C # in three ways:
1. Used in namespaces such as using System. Everyone knows this. In order not to write the full name of the class (you can write System. Console as the Console)
2. rename a class
Rename a class for ease of use, such:
Using System;
Using hahaha = System. Console;
Namespace Console001
{
Public class Class1
{
Public static void Main ()
{
Hahaha. WriteLine (second usage of using !);
}
}
}
3. Resource Management statement Function
In addition to using System, using Dos = System. Console, using in C # also provides the resource management statement function:
Using (R r1 = new R ()){
R1.F ();
}
In C #, it is translated:
R r1 = new R ();
Try {
R1.F ();
}
Finally {
If (r1! = Null) (IDisposable) r1). Dispose ();
}
Of course, r1 must support the Dispose () method.