C # using,
C # usingHttp://www.cnblogs.com/dachengxiaomeng/p/7452021.html1. using command.
The name of the using namespace.
For example:
using System;
In this way, the type in the Command space can be directly used in the program, instead of specifying the type of the detailed namespace, similar to the Java import, this function is also the most commonly used, almost every cs program is used.
For example, using System; usually appears in *. cs.
2. using alias.
Using alias = contains the specific type of detailed namespace information.
For example:
using aClass = NameSpace1.MyClass;
This method has the advantage that when the same cs references two different namespaces, but both namespaces contain the same name type. When this type is required, the detailed namespace method should be used in every place to distinguish the types with the same name. The alias method is more concise. You can declare the alias for the class you use. Note: This does not mean that the two names are repeated. If you use an alias for one of them, you do not need to use the alias for the other. If you want to use both of them, you need to use using to define the alias for both of them.
Using System; using System. collections. generic; using System. linq; using System. text; using aClass = NameSpace1.MyClass; using bClass = NameSpace2.MyClass; namespace ConsoleAppUsing {class Program {/// <summary> /// main entry point of the application. /// </Summary> [STAThread] static void Main (string [] args) {// TODO: add code here to start the application // aClass my1 = new aClass (); Console. writeLine (my1); bClass my2 = new bClass (); Console. writeLine (my2); Console. writeLine ("Press any key"); Console. read () ;}} namespace NameSpace1 {public class MyClass {public override string ToString () {return "You are in NameSpace1.MyClass ";}}} namespace NameSpace2 {class MyClass {public override string ToString () {return "You are in NameSpace2.MyClass ";}}}
3. using statement.
Define a range to process objects at the end of the range.
Scenario:
When a class instance is used in a code segment, you want to automatically call the Dispose of the class instance as long as you leave the code segment for whatever reason.
To achieve this goal, it is also possible to catch exceptions using try... catch, but it is also convenient to use using.
using (Class1 cls1 = new Class1(), cls2 = new Class1()){ // the code using cls1, cls2} // call the Dispose on cls1 and cls2