参考

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使用的更多相关文章

  1. C#委托Action、Action<T>、Func<T>、Predicate<T>

    CLR环境中给我们内置了几个常用委托Action. Action<T>.Func<T>.Predicate<T>,一般我们要用到委托的时候,尽量不要自己再定义一 个 ...

  2. 委托,C#本身的委托(Action Func)

    1.Action 分为带泛型的和不带泛型的,带泛型可传入任何类型的参数. 格式如下: using System; using System.Collections.Generic; using Sys ...

  3. (C#) Action, Func, Predicate 等泛型委托

    (转载网络文章) (1). delegate delegate我们常用到的一种声明   Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型.   例:public del ...

  4. Delegate,Action,Func,匿名方法,匿名委托,事件 (转载)

    Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) 一.委托Delegate 一般的方法(Method)中,我们的参数总是string,int,DateTime...这些基本 ...

  5. 委托(Func与Action)

    1.平时我们如果要用到委托一般都是先声明一个委托类型,比如: private delegate string Say(); string说明适用于这个委托的方法的返回类型是string类型,委托名Sa ...

  6. 委托delegate 泛型委托action<> 返回值泛型委托Func<> 匿名方法 lambda表达式 的理解

    1.使用简单委托 namespace 简单委托 { class Program { //委托方法签名 delegate void MyBookDel(int a); //定义委托 static MyB ...

  7. [转]C#委托Action、Action<T>、Func<T>、Predicate<T>

    CLR环境中给我们内置了几个常用委托Action. Action<T>.Func<T>.Predicate<T>,一般我们要用到委托的时候,尽量不要自己再定义一 个 ...

  8. 关于线程间操作无效: 从不是创建控件“xx”的线程访问它,错误解决方法(自定义委托和系统委托Action或Func解决)

    这是一个线程不安全的问题.跨线程操作问题. 比如我们需要在线程中改变textbox的文本,textbox的name是txtShowMsg 第一种方法(不推荐使用) 在窗体构造函数中写Control.C ...

  9. c# Action,Func,Predicate委托

    System命名空间下已经预先定义好了三中泛型委托,Action,Func和Predicate,这样我们在编程的时候,就不必要自己去定义这些委托了 Action是没有返回值的 Func是带返回值的 不 ...

  10. 系统内置委托Action和func

    Action委托, action是系统内置的委托,它可指向无返回值,没有参数的方法. using System; using System.Collections.Generic; using Sys ...

随机推荐

  1. Docker 搭建开源 CMDB平台 之 “OpsManage”

    说明:  我一次build 完 所以images 包 有1G多   可分层build   bash 环境一层   应用程序及启动脚本(shell.sh) 一层 步骤:           1     ...

  2. P 1035 插入与归并

    转跳点 :

  3. centos-6更新yum源(163)

    更新前请先备份原来的repo文件,养成好习惯 cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.bak 到http://mirrors ...

  4. Nachos-Lab1-完善线程机制

    Nachos是什么 Nachos (Not Another Completely Heuristic Operating System),是一个教学用操作系统,提供了操作系统框架: 线程 中断 虚拟内 ...

  5. 中文文本分类之TextRNN

    RNN模型由于具有短期记忆功能,因此天然就比较适合处理自然语言等序列问题,尤其是引入门控机制后,能够解决长期依赖问题,捕获输入样本之间的长距离联系.本文的模型是堆叠两层的LSTM和GRU模型,模型的结 ...

  6. 如何将本地项目推送到Github

    如何将本地项目推送到Github Tip:在本地要安装好Git,官网:https://git-scm.com/ 一个学习Git的好地方:https://try.github.io/ 在线闯关实战,边练 ...

  7. 六十一、SAP中的逻辑运算与进制转换

    一.代码如下 二.16进制计算过程如下 三.计算结果为16进制的11,也就是10进制的17

  8. 十五、SAP自定义结构体

    一.SAP的结构体是以BEGIN OF开始,以END OF结尾,代码如下: 二.输出结果如下

  9. 018-PHP判断文件是否存在

    <?php print("data.txt文件是否存在?" . "<br>"); if (file_exists("data.txt ...

  10. Bootstrap 侧边栏 导航栏

    http://blog.csdn.net/shangmingchao/article/details/49763351 实测效果图: