C # proxy

Source: Internet
Author: User
Today, someone asked me how to convert a method into another method.

For general 1 Program In fact, you can simply create an example and use it directly.

However, when the method to be used is ambiguous, this cannot be done. How can this problem be realized?

In fact, this issue is very simple. Just like an event, the methods you perform after an event is triggered are all written by yourself (mostly)

So how does a system know how to parse it? This is the proxy (delegate ).

I wrote an answer to his question (I think This is clearer), so I can explain how the proxy works.
// Define an agent

Private   Delegate   String Mymethod ( String Para1 );


Private   Void Page_load ( Object Sender, system. eventargs E)

{

// Example of creating a proxy (This specifies the method for creating a proxy)

Mymethod d1 =   New Mymethod (Method1 );

// Meohod2

Response. Write (method2 (D1 ));

}

// Method Method1 is a method that will be used as a batch data operation (generally used in the most recent row method). The unknown method that corresponds to an event is used as a batch data operation.

Private   String Method1 ( String Pa1)

{

Return "Parameter:" +Pa1;

}

// The method method2 is known and corresponds to an event.

Private   String Method2 (mymethod D1)

{< br> // the ignore row proxy method, method
return d1 ( " AAA " );

}

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.