C # language-05. Delegates and Events

Source: Internet
Author: User

A. Delegate: A type that defines a method signature and can be associated with any method that has a compatible signature. The so-called compatible method means that the method and the delegate's method signature have the same return type and parameter I syntax:Delegatemethod signature; 1. Method signature is the name of the method, no method body Ii. procedure for using a delegate1. Defining delegates and Delegate objects2. Writing a method to delegate3to pass a delegate's method to the delegate object4. Invoking a delegate method with a delegate Iii. multicast delegates: is to bind multiple methods that have the same method signature as the delegate to the same method1. Use the multicast delegate requirement method to return a type ofvoid. 2. Add a method to the delegate with the "+ =" number, using "-="The number is subtracted from the delegate chain by a method B. Event: is a special case of multicast delegation, the use of events has better security, avoid the delegate object is tampered with I. Syntax: Public Delegate voidEventHandler (Object sender,eventargs e); Public EventEventHandler questionevent A. Description: The sender parameter in the delegate represents the issuer of the event, and EventArgs E represents the event's Data II. EventArgs is the base class for all event arguments and does not contain data

C # language-05. Delegates and Events

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.