Using release resources

Source: Internet
Author: User

use of the Using keyword

Release resources:

Using using, or need try--catch

the Using principle:

The object is automatically reclaimed by the {}where the using is located .

The reason is that when we're going to go out {}, the system automatically calls the Dispose () method.

And that's how it's done in the DISpose method.

which objects can be used Using Recycling!

The type of the IDisposable interface must be implemented to use the using Recycle!

are managed or unmanaged resources recycled by using?

Parsing: What is managed: All C # code is supervised by the CLR,

the conclusion is that the using recycle is unmanaged Resources!

The using statement ensures that the Dispose method of a class is called at the earliest time (after the using statement is executed)as an example:using (String ss= "Diso"){//Execution Method}here the Dispose method of the string is called, and the Dispose method is called regardless of the way it exits the code block. Avoiding unexpected exceptions causes the Dispose method not to be calledusing a using statement will be invoked anyway

Using release resources

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.