action func用法记记
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void showMessage(string msg);
public static void showM(string m)
{
MessageBox.Show(m);
}
public string returnM(string m)
{
return m;
}
private void button1_Click(object sender, EventArgs e)
{
//3
showMessage s = new showMessage(showM);
s("xxx");
//1
Action<string> action = showM;
action("123");
//2
Action<string> a = X => showM(X);
a("aaaaaaaaaa");
//6
Action<string> ac = (x1) =>
{
MessageBox.Show(x1);
};
ac("111111111111111");
//6
Action<string> ac2 = delegate(string xx){
MessageBox.Show(xx);
};
ac2("222222222222");
//5
string m1 = "123";
textBox1.Invoke((Action<string>)delegate(string m)
{
textBox1.Text = m;
},m1);
textBox1.Invoke(new Action<string>((x4) =>
{
textBox1.Text = x4;
}), "aaaaax4");
//4 --需要return
Func<string, string> f = returnM;
MessageBox.Show(f("abc"));
//7
Func<string> func = delegate()
{
return "我是Func<TResult>委托出来的结果";
};
MessageBox.Show(func());
//8
Func<string, string> funcOne = delegate(string s3)
{
return s3;
};
MessageBox.Show(funcOne("我是Func<T,TResult>委托出来的结果"));
//9
Func<string, string, string> funcTwo = delegate(string value1, string value2)
{
return value1 + " " + value2;
};
MessageBox.Show(funcTwo("xxx", "我是Func<T,TResult>委托出来的结果"));
//10
Func<string, string, string> ff = (x1, x2) =>
{
return x1 + " " + x2;
};
MessageBox.Show(funcTwo("xxx", "我是Func<T,TResult>委托出来的结果"));
}
{
if (dt == null || dt.Rows.Count == 0)
{
return null;
}
IList<Model> list = new List<Model>(dt.Rows.Count);
foreach (DataRow dr in dt.Rows)
{
list.Add(func(dr));
}
return list;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = newstable();
IList<Model> list = ToList(dt, delegate(DataRow row)
{
Model m = new Model();
m.f_id =Convert.ToInt32(row["f_id"]);
return m;
});
}
}
static void Main(string[] args)
{
IList<String> list = new List<String>();
list.Add("1");
list.Add("2");
list.Add("3");
list.Add("4");
list.Add("5");
Func<String, bool> f = x => x.Equals("2");
IList<String> list2 = filter(f, list);
}
static IList<String> filter(Func<String, bool> exp, IList<String> list)
{
return list.Where(exp).ToList();
}
}
action func用法记记的更多相关文章
- Action与Func 用法
//vs2017 + framework4.6.2 //zip https://github.com/chxl800/ActionFuncDemo //源文件git https://gith ...
- VS2012 Unit Test(Void, Action, Func) —— 对无返回值、使用Action或Func作为参数、多重载的方法进行单元测试
[提示] 1. 阅读文本前希望您具备如下知识:了解单元测试,了解Dynamic,熟悉泛型(协变与逆变)和Lambda,熟悉.NET Framework提供的 Action与Func委托.2.如果您对单 ...
- (C#) Action, Func, Predicate 等泛型委托
(转载网络文章) (1). delegate delegate我们常用到的一种声明 Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型. 例:public del ...
- Lambda Action Func练习
namespace lambda { delegate void TestDelegate(string s); class Program { static void Main(string[] a ...
- Delegate,Action,Func,匿名方法,匿名委托,事件 (转载)
Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) 一.委托Delegate 一般的方法(Method)中,我们的参数总是string,int,DateTime...这些基本 ...
- MVC ---- 理解学习Func用法
//Func用法 public static class FuncDemo{ public static void TestFunc(){ //数据源 List<User> usList ...
- MVC中@Html.Action的用法
MVC项目中如果有公共部分的代码就可以单独拿出来作为控件来用(比如头部和底部代码).跟ASP.NET中的ASCX实现的效果一样,但MVC比它方便的多. 想要实现该效果,需要知道@Html.Action ...
- MVC中@Html.Action的用法(类似自定义控件)
MVC项目中如果有公共部分的代码就可以单独拿出来作为控件来用(比如头部和底部代码).跟ASP.NET中的ASCX实现的效果一样,但MVC比它方便的多. 一.@Html.Action的用法 @Html. ...
- c# Action,Func,Predicate委托
System命名空间下已经预先定义好了三中泛型委托,Action,Func和Predicate,这样我们在编程的时候,就不必要自己去定义这些委托了 Action是没有返回值的 Func是带返回值的 不 ...
随机推荐
- iOS 解压打包静态库命令
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Hannotate SC" } p.p2 { margin: 0.0px ...
- BulkSqlCopy 批量导入数据(Ef支持)
Ado.net对批量数据的支持相信大家都已经非常熟悉.再此就不在多说,就当是给自己备个份,没办法,这个方法太好用了. public static void BulkCreate( string tab ...
- leetcode 6. ZigZag Conversion
https://leetcode.com/problems/zigzag-conversion/ 题目: 将字符串转化成zigzag模式. 例如 "abcdefghijkmlnpq" ...
- linux 学习2 文件处理命令
____命令格式与目录处理命令 ____目录处理命令 ____文件处理命令 ____链接命令 ls list 菜单 命令 [-选项][参数] 选项:调整功能,多个选项可以写在一起,不分顺序. 简化选项 ...
- oracle建立数据库连接
除了全库拷贝,这个应该是oracle两个数据库之间进行数据迁移最快的方法了. CREATE PUBLIC DATABASE LINK zhengshi CONNECT TO 用户名 IDENTIFIE ...
- php上传大文件设置方法
打开php.ini,首先找到 ;;;;;;;;;;;;;;;; ; file uploads ; ;;;;;;;;;;;;;;;; 区域,有影响文件上传的以下几个参数: file_uploads = ...
- Owin SelfHost Asp.net WebApi 遇到 No type was found that matches the controller named 'ControllerName' 异常的解决方案
问题背景:在使用普通的SelfHost时,调用其它工程的dll(其实就是把WebApi写到一个单独的工程方便管理),通过加载其他工程的dll然后再访问webapi是没有问题的. 但是在使用Owin S ...
- Python 监控nginx服务是否正常
Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...
- python之路-Day5
1.列表生成式,迭代器&生成器 列表生成式 我现在有个需求,看列表[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],我要求你把列表里的每个值加1. 普通版 a = [0,1,2,3 ...
- android ListView子布局中按钮响应点击事件
只需要在子布局的根布局中添加以下属性即可: android:descendantFocusability="blocksDescendants"