C#. NET Verification Code Intelligent Recognition Learning Note---02-c#. Use of the Using keyword in net

Source: Internet
Author: User
Tags finally block

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.