In C # using keyword role and usage (Reference to God, just as with notes)

using the purpose and use of skills.

  1, reference the namespace

  2, create an alias for a namespace or type

  3, using statement

 

  1, reference namespaces, namespace This type of reference in the program instead of the detailed namespace.

    a) such as commonly used in the procedure using System.Text;

    b) a reference namespace does not mean compiler when loading assemblies that namespace is located, loading the assembly procedure depends on whether there is a call to the assembly operation, if there is no call code compiler operation will not load using the introduction of the assembly space where the namespace. Therefore, in the beginning of the source file, the introduction of multiple namespaces, not loading multiple assemblies, will not cause 'undue reference to' drawbacks

  2, create an alias for a namespace or type

      The reason is to create an alias for the introduction of the same file in different namespaces, including the type of the same name. To avoid name conflicts can be solved by setting an alias.

        例:using SGPoint = ShapMap.Geometries.Point

               Using SGPoint = System.Drawing.Point

      In fact, it can be distinguished by the type of full name, but the best solution is to use using

  3, using the statement

    using statement allows the programmer to specify object using the resources of the target resource .using statement should be used when a release must implement the IDisposable interface. This interface provides the Dispose method, which will release resources for this object

Use rules:

      a) using a type of statement can only be used to implement the IDisposable interface, ban does not support IDisposable interface type using statement, or a compile error occurs

      B) statements apply to the case of using a single cleaning unmanaged resources, and a plurality of cleaning unmanaged object is preferably implemented to try-finaly, using statements because the nested possible hidden Bug. throws an exception block when using an inner layer, the release layer is not using the resource block object

using the substance:

         Compiling the program stage, the compiler will automatically try-finally generated using statement statements and call Dispose method of the object in a finally block to clean up resources. Therefore, using try-finally statement is equivalent to the statement

Guess you like

Origin www.cnblogs.com/Damon-3707/p/11457176.html