"Go" writing high-quality Code 157 recommendations for improving C # programs--Recommendation 138: Events and delegate variables named with verbs or adjective phrases

Source: Internet
Author: User

Recommendation 138: Event and delegate variables are named using verb or adjective phrases

Events and delegate usage scenarios call a method, except that the method is assigned by the caller. This determines that the corresponding variable should be named with a verb or an adjective phrase.

Examples of proper naming of events and delegate variables are:

         Public Event Routedeventhandler Click;          Public Event Sizechangedeventhandler SizeChanged;

These two examples are the button types in WPF, which are not actually occurrences as fields of type, but instead appear as event accessors:

         Public Event Routedeventhandler Click        {            add            {                            }            remove            {                            }        }        publicevent   Sizechangedeventhandler SizeChanged        {            add            {            }            remove            {            }        }

Readers who are familiar with the property can see the event accessor as a method, so it proves from another aspect that events and delegate variables should be named by verbs or adjective phrases.

In addition to event accessors, we can also process delegates and events into fields, and the naming conventions remain the same.

Improper Practice:

         Public Event Sizechangedeventhandler Sizechangedeventhandler         {            add            {            }            remove            {            }        }

We do not recommend this. Because of the particularity of events and delegates, we can not tell whether Sizechangedeventhandler is a delegate type or a delegate variable after naming it.

Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia

"Go" writing high-quality Code 157 recommendations for improving C # programs--Recommendation 138: Events and delegate variables named with verbs or adjective phrases

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.