Lamda and anonymous functions (from www. sysoft. CC)

Source: Internet
Author: User

tag: OS uses AR SP Div on code ad line

Namespace Lamda {Public Delegate int getnum (int A, int B); // defines the delegate with return values and parameters. Class program {static void main (string [] ARGs) {getnum = delegate (int A, int B) {return a + B ;}; // directly create an anonymous function and run it. Getnum (12, 22); console. writeline (getnum (12, 22 ). tostring (); getnum ladt = (int A, int B) =>{ return a * B ;}; // The lamada method is basically the same as the preceding method. You can also write: getnum ladt = (a, B) => {return a * B}; that is, the type definition is omitted, because when the delegate is defined, type constraints have been imposed on two parameters. Or: getnum ladt = (a, B) => A * B; this is only suitable for the method body with only one line of code. Int AA = ladt (33, 22); console. writeline (AA. tostring (); console. readkey ();}}}

Use of Lamda and anonymous functions (from www. sysoft. CC)

Related Article

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.