C # Reference Type constructor

Source: Internet
Author: User

When creating an instance of the reference type,

First, allocate memory for the data fields of the instance,

Then initialize the additional fields (object pointers and synchronized block indexes) of the object ),

Finally, call the instance constructor defined in the type to set the initialization status of the object.

When constructing an object of the reference type, before calling the instance constructor of the type, the memory allocated to the object for all fields is always reset to zero or null.

The instance constructor cannot be continued. If no explicit constructor exists in the defined class,
C # The Compiler defines a default constructor. In its implementation, it simply calls the non-argument constructor of the base class.
Therefore:
Public class SomeType {}
Equivalent
Public class SomeTyoe {
Public SomeType (): base (){}
}
If the class modifier is abstract, the default constructor generated by the compiler is protected; otherwise, the class modifier is public.
If the base class does not provide a parameter-free constructor, the derived class must call a base class constructor. Otherwise, an error is returned during compilation.
If it is a static class, there is no instance constructor for the class.
You must call the constructors of the base class before accessing the fields of the base class. If the constructors of the base class are not explicitly called,
C # The Compiler automatically generates a call to the default base class constructor, and finally calls the Object constructor.

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.