C #2.0 notes on miscellaneous technologies and future development of sharp experience

Source: Internet
Author: User

I took the free time to read the course "C #2.0 sharp experience-Miscellaneous technology, and future development of C # Language" taught by Li Jianzhong. Some small knowledge points are reviewed and summarized. Here are the key points.

I. Introduction of namespace alias delimiters

C #2.0 allows us to use the namespace alias qualifier (: :) to avoid the conflict of type names in different namespaces.

1. When using the namespace alias qualifier (: :), the compiler can ensure that this is a qualifier only applicable to the "namespace alias" and will not be classified as another type or member qualifier (.)

2. the keyword globar 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. (The same namespace name and class name cause a conflict)

3. Use the namespace alias qualifier (: :) as much as possible, and reduce the use of general qualifiers such as the dot.

Ii. # pragma indicator

Code

[Obsolete]
Static void Foo (){}
Static void main (string [] ARGs)
{
# Pragma warning disable 612
Foo ();
# Pragma warning restore 612
}

Note:

1. Currently, only the Pragma indicator is supported # pragma warning

2. # pragma warning disable any compiler warning information

3. # pragma warning Restore can restore any compiler warning information that is disable.

4. You can follow the specific warning code after disable and restore to disable or recover specific warning information.

5. # pragma is a compiler preprocessing function that does not affect any code running mechanism.

Iii. Protection Level of the property accessors

C #2.0 allows us to use different access level modifiers for get and set accessors of an attribute:

Public string name
{
Get {return name ;}
Private set {name = value ;}
}

 

Note:

1. The access modifier of the application on the property accessor (get or set) must be "less than" (more strict), for example, protected is less than public

2. You can only specify the access modifier "smaller" than the access modifier "on an attribute accessor (get or set.

3. the attribute declaration in the interface cannot specify any access modifier for the attribute accessor (get or set). It can only be set to public by default.

4. The change rules at the protection level of the attribute accessors apply completely to the C # indexer (but the indexer cannot be declared as static ).

Best regards,

Charles Chen

Http://charles2008.cnblogs.com/

 

 

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.