标签:style blog color line div new
//预计算和缓存示例
static void Main(string[] args)
{
//第一种方法
var add = CalcFunc();
Console.WriteLine(add(10)(20));
var add30 = add(30);
var add40 = add30(40);
Console.WriteLine(add40);
Console.Read();
}
// 定义函数,返回一个调用函数
static Func<int, Func<int, int>> CalcFunc()
{
return x =>
{
return y => x + y;
};
}
//预计算和缓存示例 static void Main(string[] args) { List<string > list = new List<string>(); list.Add("one"); list.Add("two"); list.Add("three"); list.Add("four"); var fun1 = FindStr(list); Console.WriteLine(fun1("two")); Console.Read(); } //作用缓冲 static Func<string , bool> FindStr(List<string > lst) { HashSet<string > hsSet = new HashSet<string >(lst); return item => { return hsSet.Contains(item); }; }
标签:style blog color line div new
原文地址:http://www.cnblogs.com/zjgtlkj/p/3839832.html