c#Func简单使用
来源:互联网 发布:数据挖掘pdf 编辑:程序博客网 时间:2024/05/17 07:31
private Func<string, string> TestFun() { Func<string, string> fun = k => k.ToUpper(); return fun; } private Func<string, string, bool> HandderCondition() { Func<string, string, bool> kk = (x, w) => x.Length > 5 && x.Contains(w); return kk; }
string[] arr = { "orange", "apple", "Article", "elephant", "star", "and" }; string name = "Dakota"; Response.Write(TestFun()(name) + "<br />"); // var query = arr.Where(x => HandderCondition()(x, "a")).Select(t => t); foreach (var item in query) { Response.Write(item + "<br />"); }
输出:
DAKOTA
orange
elephant
Func<double, double> myfunc = (x) => 2.0 * x * x - 0.5 * x; Console.WriteLine(myfunc(1)); //1.5 //or Console.WriteLine((myfunc = (x) => 2.0 * x * x - 0.5 * x)(1)); //1.5 //阶层函数 Func<Func<int, int>, Func<int, int>> F = factorial => n => n == 0 ? 1 : n * factorial(n - 1); //一个参数的括号可以省略 //Func<int, Func<int>> fa = (x) => () => x * 3; Func<int, Func<int>> fa = x => () => x * 3; //Func<int, Func<int, int>> fb = (x) => (y) => x * y; Func<int, Func<int, int>> fb = x => y => x * y; Console.WriteLine("fa:{0}, fb:{1}", fa(10)(), fb(10)(5)); //30,50
0 0
- c#Func简单使用
- Func和Action委托的区别和简单使用
- Func和Action委托的区别和简单使用
- Func和Action委托的区别和简单使用
- C# Func<参数列表>
- 如何使用 Boost.Func
- Action以及Func使用
- Func<>结合Dictionary使用
- C/C++ void func() const
- Lambda 表达式创建委托Action和Func时的简单使用
- func
- func
- Sqlalchemy中Func的使用
- typedef的使用...typedef int (*Func)(int,int); Func func = sum;
- System.Func<>与System.Action<> 简单对比
- typedef void(*Func)(void)的简单用途
- swift简单学习之函数(func)
- 简单的action和Func应用
- Java线程池
- 黑马程序员--字符串类
- 基于注解的SPRINGMVC+FREEMARKER环境搭建
- iOS7修改状态栏文字颜色
- 进度条的暂停和开始
- c#Func简单使用
- android 学习 sqlite
- gson的@Expose注解和@SerializedName注解
- 企业面试题:一个三个数的式子,移动其中一根火柴,使等式成立,用程序或实现(可以用伪码),输出能成立的等式。
- ddfgdgdfgdfg
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Spring MVC框架搭建及详解
- Java进阶学习路线图
- os.path模块