[C # Learning Note] a question on csdn

Source: Internet
Author: User

The hidden methods in delegation are somewhat confusing. Please give instructions by experts.
The three paragraphs belowCodeWhat is the difference between code1, code2, and code3? It is best to give a detailed description.

 

Code1:

 
Using system; namespace consoleapplication1 {class program {delegate string delegatetest (string Val); static void main (string [] ARGs) {string mid = ", middle part ,"; delegatetest anondel = delegate (string PARAM) {Param + = mid; Param + = "and this is added to the string. "; return Param ;}; console. writeline (anondel ("Start of string "));}}}

Code2:

 

Using system; namespace consoleapplication1 {class program {delegate string delegatetest (string Val); static string mid = ", middle part,"; static void main (string [] ARGs) {delegatetest anondel = new delegatetest (delmethod); console. writeline (anondel ("Start of string");} static string delmethod (string PARAM) {Param + = mid; Param + = "and this is added to the string. "; return Param ;}}}

 

Code3:

Using system; namespace consoleapplication1 {class program {delegate string delegatetest (string Val); static void main (string [] ARGs) {string mid = ", middle part ,"; delegatetest anondel = new delegatetest (delegate (string PARAM) {Param + = mid; Param + = "and this is added to the string. "; return Param;}); console. writeline (anondel ("Start of string "));}}}

 

 

I just learned about delegation. I will answer O (∩ _ ∩) O Haha ~

 

Code1 and code3 should both be anonymous, and code2 should be standard. Code1 and code3 are only issues in writing.

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.