Truth series ~ The second is the constructor and the analysis function. You begin, I am the final!

Source: Internet
Author: User

Back to directory

Concept and understanding

First of all, constructor and destructor refer to classes. Therefore, the following statements are for class objects.

Contructor is a Contructor called by the Americans. When a Class Object performs a new operation, it will execute the specified constructor according to your formal parameters.

The Destructor is called Destructors by Americans. It refers to the method to be executed when the class in which it belongs is ineffective. It is generally used to clean up some things, release the memory it occupies (the occupied memory is occupied after the new operation.. net ).

Execution sequence of constructor and destructor when class inheritance occurs

1. Execution of constructor: the constructor of the base class is always executed before the constructor of the base class is executed.

2. Execute the Destructor: You will always first execute your own destructor (release your own class resources) before executing the destructor of its base class.

Let's take a look at the code below:

~~

Check the execution result.

Generally, when using unmanaged resources in a project, we should rewrite the class destructor to manually release resources and disable unnecessary resources.

~ Dispose (IDisposable Member)

In fact. net, there are a lot of unmanaged resources (.. net resources cannot be controlled during runtime. It may be associated with the local network, local computer, network server, data server, and network topology.

). They are File objects, database objects (DbConnection), network Socket objects (Socket), and so on.

Back to directory

Related Article

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.