Use a LINQ Lambda expression as a generic Activity

Source: Internet
Author: User
   
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. diagnostics; using system. io; namespace lambdaexpressionaction {class program {static void main (string [] ARGs) {// action: Generic delegate, you can capture a behavior as an callable object. // you only need to provide the parameter type for the action and assign it a Lambda expression. // you can define the delegate of an output string, S is the output string, and textwriter is an output instance, such as console action <string, textwriter> output delegate = (S, writer) => writer. writeline (s); // set" Console "string outputs the delegate in the console (" console displays the output string! ", Console. out); // define an output stream to write the string to the last row of the "C: \ temp \ text.txt" text file streamwriter stream = file. appendtext ("C: \ temp \ text.txt"); // if the user expects immediate feedback from the device you write, set autoflush to true stream. autoflush = true; // call the output delegate ("system. the output string is displayed in Io! ", Stream); console. Readline ();}}}

 

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.