"Clr.via.c# Third Edition" Part II 8th, Chapter 9 reading notes (iv)

Source: Internet
Author: User

Three types of construction methods:

Instance constructor (reference type): the instance constructor can never be inherited (so there are no modifiers before the method), and if the class's modifier is static (sealed and abstract), the compiler does not generate a default constructor in the class's definition at all.

Important cognition: To make the code "verifiable," the class's instance constructor must call the base class's constructor before accessing any fields inherited from the base class. If the constructor of a derived class does not appear to call a base class constructor, the C # compiler automatically generates a call to the default base class constructor.

The fields declared in the class are actually initialized in the code that is converted to the constructor in the compiler. If there are 3 fields and 3 constructors in a class, then the compiler actually generates three times the code that initializes 3 fields-once per constructor.

Instance constructor (value type): The C # compiler does not allow a value type to define a parameterless constructor (can be a parameter).

Type constructors (static constructors): You can define only one, no parameters, and common constructors to coexist, to set the initial state of the type instance. Its invocation is the responsibility of the CLR. It executes only once (multi-threaded).

Extension methods:

C # extension method: Allows you to define a static method and invoke it using the syntax of the instance method. (just add the This keyword before the first parameter of the method)

Parameters:

When declaring a method's parameter type, you should try to specify the weakest type, preferably an interface rather than a base class. (ref, out, params are explained)

Sentiment: This book explains C # This programming language, all from the compiler, the CLR's execution principle angle, very deep. These two chapters personally feel nothing particularly important, so list some important concepts and be familiar with these concepts.

"Clr.via.c# Third Edition" Part II 8th, Chapter 9 reading notes (iv)

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.