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