1 Class Someclass // Delegated class
2 {
3 Public d Elegate String Ftxdelegate ( String S); // note that the delegate must be in lower case. This is the keyword. In addition, public must pay attention to the consistency of access.
4 }
1 ClassSomeclass2
2 {
3 PublicFtxdelegate ftx;//This is the delegate variable.
4 }
Usage
1
Someclass2.ftx = new ftxdelegate (...); // use the target function instead ().
2 String resultstr = Someclass2. Ftx (somestr );
3
Example: case-sensitive Conversion
1 Public Class Capital
2 {
3 Public String Fixtext ( String S)
4 { Return S. toupper ();}
5 }
6
7 Public Class Lower
8 {
9 Public Static String Fixtext ( String S)
10 { Return S. tolower ();}
11 }
12
13 // Form
14 Private Void Opcap_checkedchanged ( Object Sender, eventargs E)
15 {
16 Btprocess. Enabled = True ;
17 Ftx = New Ftxdelegate ( New Capital (). fixtext); // do not have ()
18 // This is an instance
19 }
20
21 Private Void Oplower_checkedchanged ( Object Sender, eventargs E)
22 {
23 Btprocess. Enabled = True ;
24 Ftx = New Ftxdelegate (lower. fixtext); // do not ()
25 // This is a static method.
26 }
27
28
29 Private Void Btprocess_click ( Object Sender, eventargs E)
30 {
31 String S = Ftx (txname. Text );
32
33 }