C # getting started with Lambda,

Source: Internet
Author: User

C # getting started with Lambda,

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. text; 5 6 namespace LambdaSample 7 {8 class Program 9 {10 static void Main (string [] args) 11 {12 int [] myIntArray = {1, 2, 3, 4, 5}; 13 // The accumulators calculate the total number of arrays. 14 int result = myIntArray. aggregate (paramA, paramB) => paramA + paramB); 15 int result1 = myIntArray. aggregate <int> (paramA, paramB) => paramA + paramB); 16 int result2 = myIntArray. aggregate <int, int> (0, (paramA, paramB) => paramA + paramB); 17 // recursively calculates the total number of arrays 18 int result3 = count (5); 19 Console. writeLine ("The Result is:" + result); 20 Console. writeLine ("The Result1 is:" + result1); 21 Console. writeLine ("The Result2 is:" + result2); 22 Console. writeLine ("The Result3 is:" + result3); 23 24 string [] myStrArray = {"Admin", "Change", "ByPage "}; 25 // string Array splicing question 26 string strResult = myStrArray. aggregate (paramA, paramB) => paramA + "" + paramB); 27 // The total length of the string array is calculated as 28 int result4 = myStrArray. aggregate <string, int> (0, (a, B) => a + B. length); 29 // string Array splicing 2, adding the string "Some curries:" 30 string strResult1 = myStrArray. aggregate <string, string> ("Some curries:", (a, B) => a + "" + B); 31 // calculate the total length of the string array 2 hovertree. com32 int result5 = myStrArray. aggregate <string, string, int> ("Some curries:", (a, B) => a + "" + B, a =>. length); 33 Console. writeLine ("The StrResult is:" + strResult); 34 Console. writeLine ("The Result4 is:" + result4); 35 Console. writeLine (strResult1); 36 Console. writeLine ("The Result5 is:" + result5); 37 Console. readKey (); 38} 39 40 static int count (int n) 41 {42 if (n = 1) 43 {44 return 1; 45} 46 return n + count (n-1); 47} 48} 49}

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.