C #2.0 _ 3-local type, attribute accessors protection level, namespace alias qualifier

Source: Internet
Author: User
Local type

In C #1.0, a class can only be placed in one file. In C #2.0, a keyword "partial" is used to divide a class into two parts [that is, the implementation of a class can be in multiple files]. The compilation result is exactly the same as that written in a file. More significance lies in engineering management.

The value of the local type is applicable to interfaces, classes, or structures. enumeration is not supported. [generally, enumeration is not so large.]

Each part of the same type must have a modifier partial, which must be in the same namespace and must be compiled and accessed simultaneously;

The keyword partial is a context keyword. It indicates a keyword only when it is put together with class, struct, and interface;

The features and interfaces of local types have a cumulative effect;

If one part of a type uses the abstract modifier, the entire class will be treated as an abstract class;

If a part of a type uses the sealed modifier, the entire class is regarded as a sealed class;

Different parts cannot use conflicting modifiers. For example, abstract and sealed cannot be used on one part;

The base classes specified on each part must be consistent. Some parts do not specify the base class, but if they are specified, they must be the same.

Attribute accessors Protection Level

C #2.0 allows get and set accessors of an attribute to use different access level modifiers [Note the concept of attribute accessors and attributes].

The access modifier on the property accessors (get or set) must be stricter than the access modifier of the property;

You can only specify the access modifier on one property accessor (get or set), and the other uses the access modifier of the property by default;

The attribute in the interface can only be public by default, and the access modifier of the property accessor (get or set) cannot be set.

Namespace alias qualifier

C #2.0 allows the namespace alias qualifier (: :) to avoid type conflicts in different namespaces. When the namespace alias qualifier (: :) the compiler can ensure that this is a qualifier for "namespace alias" only [view the code in IL Code :], it is not classified as another type or a member qualifier (.). The keyword global can be placed on the left of the namespace alias qualifier (: :), which allows the compiler to only search for all namespaces, rather than other types or members. Use the namespace alias qualifier (: :) as much as possible, and reduce the use of general qualifiers such as dot (.) [Accelerate the compiler search type, no difference after compilation].

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.