Delegate format (proxy or delegate)

Source: Internet
Author: User
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 }

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.