C # define events

Source: Internet
Author: User

 

1 /**//*
A custom event of 2 * C #
3 */
4 using system;
5 namespace defaultnamespace
6 {
7 class delegateclass
8 {
9 Public Delegate bool comparator (INT one, int two); // declare the proxy
10 public event comparator oncomparator; // defines an event
11 Public void startcomparator () // event trigger method. If you call this method, all registered events are triggered.
12 {
13 oncomparator (3, 4 );
14}
15}
16
17 class delegatedemo
18 {
19 //??????
20 public bool sortasceding (INT one, int two)
21 {
22 // return one> Two;
23 console. writeline ("sortasceding:" + one + "," + two );
24 return true;
25}
26 //??????
27 public bool sortdescending (INT one, int two)
28 {
29 // return two> one;
30 console. writeline ("sortdescending" + one + "," + two );
31 return true;
32}
33
34 public static void main (string [] ARGs)
35 {
36 // proxy object
37 delegateclass Dc = new delegateclass ();
38 // customer object
39 delegatedemo dd = new delegatedemo ();
40 // register the event
41 DC. oncomparator + = new delegateclass. comparator (DD. sortasceding );
42 DC. oncomparator + = new delegateclass. comparator (DD. sortdescending );
43 DC. oncomparator + = new delegateclass. comparator (DD. sortdescending );
44 DC. oncomparator + = new delegateclass. comparator (DD. sortdescending );
45 // event triggered
46 DC. startcomparator ();
47
48}
49}
50}
51

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.