C#. NET Verification Code Intelligent Recognition Learning Note---02-c#. Use of the Using keyword in net
Technical QQ Exchange Group: javadream:251572072
Tutorials Download, online exchange: it.yunsit.cn
--------------------------------------------------
The tutorial should be used, this knowledge point, picked out.
---------------------------------------------
1.using usage and usage tips.
1. Reference namespaces
2. Create an alias name for a namespace or type
3. Use using statement
1. Reference the namespace so that you can reference the type of the namespace in your program without having to specify a detailed namespace.
A) such as the use system.text commonly used in the program;
b) The reference namespace does not equal the assembly where the namespace is loaded when the compiler compiles, and the assembly's load is determined by whether there is a call operation in the program for that assembly.
If there is no call operation in the code, the compiler will not load the assembly using the namespace that was introduced into the namespace. Therefore, at the beginning of the source file, introduce multiple namespaces,
does not load multiple assemblies, does not cause ' over-referencing ' drawbacks
2. Create an alias name for a namespace or type
Aliases are created because the same name is included in the same file that is introduced into different namespaces.
To avoid name collisions, you can set up aliases to resolve them.
Example: Using Sgpoint = ShapMap.Geometries.Point
Using Sgpoint = System.Drawing.Point
It can also be distinguished by the full name of the type, but the best solution is to use the using
3. Using statements
The using statement allows the programmer to specify when the object that uses the resource should release the resource. The object used in the using statement must implement the IDisposable interface. This interface provides the Dispose method,
The method frees the resource for this object
Usage Rules:
A) using statement can only be used to implement the type of the IDisposable interface, prohibit the use of using statements for unsupported IDisposable interface types, or compile errors will occur
b) The using statement is suitable for cleaning up a single unmanaged resource, while the cleanup of multiple unmanaged objects is best achieved by try-finaly.
A hidden bug may exist because of nested using statements. An object resource for an outer using block cannot be freed when an exception is thrown by an inner using block
Using substance:
During the program compilation phase, the compiler automatically generates the using statement with the Try-finally statement and calls the object's Dispose method in the finally block.
To clean up resources. Therefore, the using statement is equivalent to the try-finally statement.
--------------------------------------------------------------------------------
C#. NET Verification Code Intelligent Recognition Learning Note---02-c#. Use of the Using keyword in net