C#入门经典Lambda

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace LambdaSample
{
class Program
{
static void Main(string[] args)
{
int[] myIntArray = { ,, , , };
//累加器计算数组总和
int result = myIntArray.Aggregate((paramA, paramB) => paramA + paramB);
int result1 = myIntArray.Aggregate<int>((paramA, paramB) => paramA + paramB);
int result2 = myIntArray.Aggregate<int, int>(, (paramA, paramB) => paramA + paramB);
//递归计算数组总和
int result3 = count();
Console.WriteLine("The Result is: " + result);
Console.WriteLine("The Result1 is: " + result1);
Console.WriteLine("The Result2 is: " + result2);
Console.WriteLine("The Result3 is: " + result3); string[] myStrArray = { "Admin", "Change", "ByPage" };
//字符串数组拼接 何问起
string strResult = myStrArray.Aggregate((paramA, paramB) => paramA + " " + paramB);
//字符串数组字符串总长度计算
int result4 = myStrArray.Aggregate<string, int>(, (a, b) => a + b.Length);
//字符串数组拼接2,增加字符串"Some curries: "
string strResult1 = myStrArray.Aggregate<string, string>("Some curries: ", (a, b) => a + " " + b);
//字符串数组字符串总长度计算2 hovertree.com
int result5 = myStrArray.Aggregate<string, string, int>("Some curries: ", (a, b) => a + " " + b, a => a.Length);
Console.WriteLine("The StrResult is: " + strResult);
Console.WriteLine("The Result4 is: " + result4);
Console.WriteLine(strResult1);
Console.WriteLine("The Result5 is: " + result5);
Console.ReadKey();
} static int count(int n)
{
if (n == )
{
return ;
}
return n + count(n - );
}
}
}

转自:http://hovertree.com/h/bjaf/jf9yeju1.htm

参考:C# Lambda 实例代码 深入浅出Lambda表达式 C#泛型详细介绍

开发技术文章收集: http://www.cnblogs.com/sosoft/p/kaifajishu.html

上一篇:“System Volume Information”文件夹里的NTFS木马(安全问题)


下一篇:MyEclipse里项目部署到tomcat上之后,tomcat webpps文件夹里为什么找不到这个项目