委托、Action、Func使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApp1
{
class Program
{
// private delegate void BuyBook();
static void Main(string[] args)
{ //BuyBook buybook = new BuyBook(Book);
//buybook();
//Action<string> BookAction = new Action<string>(Book);
//BookAction("百年孤独");
//Func<string> RetBook = new Func<string>(FuncBook);
//Console.WriteLine(RetBook());
//Func<string, string> RetBook = new Func<string, string>(FuncBook);
//Console.WriteLine(RetBook("aaa"));
Func<string> funcValue = delegate
{
return "我是即将传递的值3";
};
Func<List<Student>> funcValue2 = delegate
{
List<Student> list = new List<Student>()
{
new Student(){SName="张同学",SAge=11,Ssex="男"},
new Student(){SName="李同学",SAge=12,Ssex="男"},
new Student(){SName="王同学",SAge=13,Ssex="男"},
new Student(){SName="赵同学",SAge=14,Ssex="男"},
};
return list;
};
DisPlayValue(funcValue);
DisPlayValue2(funcValue2);
Console.ReadKey();
}
private static void DisPlayValue(Func<string> func)
{
string RetFunc = func();
Console.WriteLine("我在测试一下传过来值:{0}", RetFunc);
}
private static void DisPlayValue2(Func<List<Student>> func)
{
List<Student> list = new List<Student>();
list = func(); }
public static void Book(string BookName)
{
Console.WriteLine("我是买书的是:{0}", BookName);
}
public static string FuncBook()
{
return "送书来了";
}
public static string FuncBook(string BookName)
{
return BookName;
}
}
public class Student
{ public string SName { get; set; } public int SAge { get; set; } public string Ssex { get; set; }
}
}
委托、Action、Func使用的更多相关文章
- C#委托Action、Action<T>、Func<T>、Predicate<T>
CLR环境中给我们内置了几个常用委托Action. Action<T>.Func<T>.Predicate<T>,一般我们要用到委托的时候,尽量不要自己再定义一 个 ...
- 委托,C#本身的委托(Action Func)
1.Action 分为带泛型的和不带泛型的,带泛型可传入任何类型的参数. 格式如下: using System; using System.Collections.Generic; using Sys ...
- (C#) Action, Func, Predicate 等泛型委托
(转载网络文章) (1). delegate delegate我们常用到的一种声明 Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型. 例:public del ...
- Delegate,Action,Func,匿名方法,匿名委托,事件 (转载)
Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) 一.委托Delegate 一般的方法(Method)中,我们的参数总是string,int,DateTime...这些基本 ...
- 委托(Func与Action)
1.平时我们如果要用到委托一般都是先声明一个委托类型,比如: private delegate string Say(); string说明适用于这个委托的方法的返回类型是string类型,委托名Sa ...
- 委托delegate 泛型委托action<> 返回值泛型委托Func<> 匿名方法 lambda表达式 的理解
1.使用简单委托 namespace 简单委托 { class Program { //委托方法签名 delegate void MyBookDel(int a); //定义委托 static MyB ...
- [转]C#委托Action、Action<T>、Func<T>、Predicate<T>
CLR环境中给我们内置了几个常用委托Action. Action<T>.Func<T>.Predicate<T>,一般我们要用到委托的时候,尽量不要自己再定义一 个 ...
- 关于线程间操作无效: 从不是创建控件“xx”的线程访问它,错误解决方法(自定义委托和系统委托Action或Func解决)
这是一个线程不安全的问题.跨线程操作问题. 比如我们需要在线程中改变textbox的文本,textbox的name是txtShowMsg 第一种方法(不推荐使用) 在窗体构造函数中写Control.C ...
- c# Action,Func,Predicate委托
System命名空间下已经预先定义好了三中泛型委托,Action,Func和Predicate,这样我们在编程的时候,就不必要自己去定义这些委托了 Action是没有返回值的 Func是带返回值的 不 ...
- 系统内置委托Action和func
Action委托, action是系统内置的委托,它可指向无返回值,没有参数的方法. using System; using System.Collections.Generic; using Sys ...
随机推荐
- leetcode1162 As Far from Land as Possible
""" Given an N x N grid containing only values and , represents water and represents ...
- NOR Flash驱动
驱动程序 1 ] ] );81 ;83 }84 85 86 static void __exit nor_exit(void)87 {88 iounmap(nor_ ...
- G - Traffic
vin is observing the cars at a crossroads. He finds that there are n cars running in the east-west d ...
- zTree第二次
需要注意的是:动态生成的树节点数据不是在后面拼接的,而是直接在done里面 <!DOCTYPE HTML> <HTML> <HEAD> <TITLE> ...
- MongoDB_04_插入和查询
案列需求: 存在文章评论的数据存放到MongoDB中,数据结构参考如下: 数据库:articledb 专栏文章评论 comment / / 字段名称 字段含义 字段类型 备注 _id ID Objec ...
- Golang的单目(一元)运算符-地址操作符和接收操作符
Golang的单目(一元)运算符-地址操作符和接收操作符 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Golang的单目(一元)运算符概述 常见的地址操作符: &: ...
- 采用idea创建springboot mybatis web工程
idea是一款强大的利器,最近公司换成采用springboot在eclipse上开发,因为idea的强大,故而,学习一下该利器,搭建springboot的web工程,在下面练习使用. 一.创建spri ...
- REST接口
全名是Representational State Transfer REST是设计风格而不是标准 建议将JSON格式作为标准响应格式 -------------------------------- ...
- 《thinkphp》二、创建实例
1.目录结构 project 应用部署目录 ├─application 应用目录(可设置) │ ├─common 公共模块目录(可更改) │ ├─index 模块目录(可更改) │ │ ├─confi ...
- SciKit-Learn 可视化数据:主成分分析(PCA)
## 保留版权所有,转帖注明出处 章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Le ...