参考

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. PHP处理大数据量老用户头像更新的操作--解决数据量大超时的问题

    /** * @title 老用户头像更新--每3秒调用一次接口,每次更新10条数据 * @example user/createHeadPicForOldUser? * @method GET * @ ...

  2. mysql合并结果集

  3. 如何拯救被Due逼疯的留学生们?

    Final季又到了,还有多少paper,多少project没完成?每年一到这个时候,手忙脚乱赶各种进度就成了留学小伙伴们共同的日常.任务多,不知道从何开始,拖延,烦躁……到底该怎么办?小编今天为各位介 ...

  4. 自己写个tween

    public Vector3 begin,end;//起始终止坐标 public float BtoE_time;//用时 float timer,lerp;//计时器和进度值 void Update ...

  5. GeneWise

    GeneWise是用于将蛋白质序列进行同源预测的软件

  6. Golang的变量定义及使用案例

    Golang的变量定义及使用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.变量的定义 package main import "fmt" func m ...

  7. namenode节点无法自动切换主从

    当停掉主namenode节点,从节点无法切换到active状态,有两种可能导致这种问题 1.查看namenode上的zkfc日志,发现没有fuser命令,需要手动安装 yum install -y p ...

  8. [CSS]水平垂直居中方案

    简单总结一下常用的水平垂直居中方案 直接在父级元素设置 text-align 和 line-height ,针对未浮动的行内元素 <div class="box"> & ...

  9. 吴裕雄--天生自然C++语言学习笔记:C++ 接口(抽象类)

    接口描述了类的行为和功能,而不需要完成类的特定实现. C++ 接口是使用抽象类来实现的,抽象类与数据抽象互不混淆,数据抽象是一个把实现细节与相关的数据分离开的概念. 如果类中至少有一个函数被声明为纯虚 ...

  10. Win7微信DLL劫持反弹SHELL(10.9 第十七天)

    (该文参考自网络其他人资料,仅为学习,不得用于非法用途) 准备的工具:kali虚拟机 W7虚拟机 微信 ProcessExplorer the-backdoor-factory-master 打开微信 ...