ASP. NET learning notes (5) Delegation

Source: Internet
Author: User

Instance:
I. Use of delegation
1. Declare a delegate
2. Pass the delegate as a parameter
3. Call the corresponding method based on the input delegate

 

Ii. Delegation Summary
1. The delegate only contains the method address.
2. Avoid using a large number of conditional statements and make the program more scalable.

Iii. multicast Delegation

1. The status of the delegate as a parameter is the same as that of string, so it can be declared as follows

2. Delegation is different from a string feature: multiple methods can be assigned to the same delegate, which is both a multicast delegate.
When this delegate is called, the bound methods are called in sequence.

3. Use "=" for the first time and "+ =" for the second time.


4. Similarly, You can unbind a delegate.

 
By: dxh_0829
 

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.