Method 2: attribute CLR Lesson 9

Source: Internet
Author: User

1. The static (type) constructor should not call the static (type) constructor in the base class because the static field is not inherited by the derived class (

That is, objects such as static fields defined in the parent class cannot be accessed in their child classes .), A class can have only one static constructor and must

There is no parameter.
2. When necessaryProgramWhen the domain is closed, someCodeUse the domainupload event of system. appdomain.

Iii. CLR assume that all method parameters are delivered by value. When a parameter is an object of the same type, the parameter can be passed

To reference (or pointer) the object. The parameter corresponding to the value type is passed to the method as a copy of the Value Type instance.

. This means that the method gets a copy of its own value type instance, and the instance in the code that calls this method will not be affected.

.
4. Out: You can skip initialization before calling the API. You must assign a value to the out parameter before returning the API. The called method cannot directly read

Value. Ref must be initialized before calling. You can define the ref overload, but the ref overload is the same as the out overload. All

During loading, if both ref and out are reloaded, the other of them will not work. Because the Il code generated by the compiler is the same.

5. the variables passed by reference must be of the same type as the parameters declared by the method (that is, if the method is an object-type parameter

When using this method, you must change the parameter to convert it to an object before passing it in ).

6. Variable Number Parameter: Param, which is the last parameter of the method, but must be the last parameter.

7. New keywords. Used to hide methods with the same name in the base class.

8. attribute: No parameter attribute (Intelligent field), including the parameter attribute (the parameter attribute in C # Is the indexer ).
Defining an attribute is that the compiler will generate the following three items in the managed heap: 1. A get accesser method that represents the attribute. 2. A Set

Attribute accessors (methods 1 and 2 must be available only when the get or set accessors are defined ). 3. An owner in the metadata of the managed stack Module

The attribute of read-only, write-only, or read/write. Attribute is just a class method.

The upper "GET _ + attribute name" and "SET _ + attribute name" constitute a method, which contains two parameter attributes (Indexer) and cannot be named. Get_item,

Set_item generate the corresponding method (you can set the feature to modify the item so that other index method names change ).

9. indexer: The indexer must have at least one or more parameters and can be reloaded. Using object as the parameter

It is a common method in array query. hashtalbe must be an object-type indexer. The index value of the indexer can be

It can be a number, a character, or a string. The Set Method of the index has an implicit parameter of value, just like the non-parameter attribute. The

The parameter indicates the new value expected by the indexed element. CLR does not distinguish between the parameter-free attribute and the parameter-included attribute. For the CLR attribute rescue class

Type. The index indexer (including the parameter attributes) will also generate three objects (article 8) Just as there is no parameter attribute ).

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.