Delegate class (delegate)

Source: Internet
Author: User

A delegate is a class that defines the type of a method so that the method can be passed as a parameter of another method. This way, the method is dynamically assigned to the parameter, which can be avoided inProgramA large number of IF-else (switch) statements are used, and the program has better scalability.

A delegate is a reference type, so it has the connectivity of the reference type. It saves not actual values, but references to objects stored in managed heap. What references does it save? The delegate stores references to the function.

Use the delegate keyword in C # To define the delegate, and then use the familiar function call syntax to call the delegate.

Delegation is the basis of events.

The delegate is similar to the function pointer in C ++. However, the delegate type is safe and reliable.

The delegate allows passing methods as parameters.

A delegate can be used to define a callback method.

The delegate can be linked together. For example, multiple methods can be called for an event.

The method does not need to be exactly matched with the delegate signature.

There are three steps to define and use delegation: Declaration, instantiation, and call.

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.