委托调用方法的4种方式。

using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
delegate void DelFunc(string a);
//delegate void FUNC<int ,int,string>( );
class Program
{ public static void Fun1(string str)
{
List<int> list = new List<int>();
Dictionary<int, object> dic = new Dictionary<int, object>();
Console.WriteLine(str+"new");
}
public static void Fun2(string str)
{
Console.WriteLine(str + "非new"); }
static void Main(string[] args)
{
DelFunc del = new DelFunc(Fun1);
del += Fun2;
del += delegate(string str)
{
Console.WriteLine(str+"匿名方法");
};
del+=str=>Console.WriteLine(str+"lamada表达式");
del("赋值给委托变量,通过"); Console.ReadKey();
}
}
}

new,+=,delegate匿名方法,lamada表达式(就是方法,匿名的)

委托约束方法的 参数返回值,泛型约束参数返回值的类型。

 namespace ConsoleApplication1
{
//委托,规定返回值和参数,泛型<>,规定参数和返回值类型。
delegate T3 Del<T1, T2, T3>(T1 m, T2 n);//定义:只写T,不写具体的类型,<>里 输入和返回。( )参数,并没有返回值** class Program
{
public static string Delfun1(string str1, string str2)
{
Console.WriteLine();
return str1 + str2;
}
public static string Delfun2(string str1, string str2)
{
Console.WriteLine();
return str1 + str2 + "第二个方法";
}
static void Main(string[] args)
{
{
//new或=或+=时,指向的方法必须具体和其委托匹配的参数返回值 类型。
Del<string, string, string> DelEntity = new Del<string, string, string>(Delfun1);
DelEntity += Delfun2;
DelEntity += delegate(string str1, string str2) { Console.WriteLine(); ;return str1 + str2 + "第三个方法"; };
DelEntity += (string str1, string str2) => { Console.WriteLine(); return str1 + str2 + "第四个方法"; };
//最后调用,传具体和其委托匹配的参数值
Console.WriteLine(DelEntity("字符串1", "字符串2"));
Console.ReadKey();
}
}
}
}

泛型委托。写一个模仿的 delegate T2 Func(in T1,out T2)(T1 arg)

Func的超强分析

 using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
//Where Find OrderBy Take Skip //委托,规定返回值和参数,泛型<>,规定参数和返回值类型。
//delegate T3 Del<in T1, in T2, out T3>(T1 m, T2 n);//定义:只写T,不写具体的类型,<>里 输入和返回。( )参数加个in,并没有返回值加out**
//public delegate TResult Func<in T, out TResult>(T arg);
class Program
{
public static bool fun(string str)
{
if (str.Contains("aa"))
{
return true;
}
else
{
return false;
}
}
static void Main(string[] args)
{
List<string> list = new List<string>() { "aa", "bb", "dd" };//using System.Collections.Generic;
//public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
//where是IEnumerable<TSource>泛型接口的扩展(泛型)方法。 //public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
//List<>继承了IEnumerable<TSource>泛型接口,所以具有where方法。 //此扩展泛型方法存放的位置,是写在public static class Enumerable类里面 //当list<T>确定里面的元素类型,比如string,父类接口 IEnumerable<T>也会确定其类型,
//父类接口 IEnumerable<T>的扩展泛型方法where<T>其的参数Func<T,bool>,T也会确定其类型。
//一般where<T>的T可以省略。 //where(Func)中的Func是对这个集合的每一项( 每一项变量=>条件方法体)进行查询,符合条件方法体的返回true
//where方法返回这样多个元素就是IEnumerable<T>集合,用其接受,再foreach遍历。 //第一Func委托类型的一个委托变量对应的lamada表达式
//IEnumerable<string> temp = list.Where<string>(i => i.Contains("a"));//using System.Linq;
//第二Func委托类型的一个委托变量,事先已经指向定义好的函数
//Func<string, bool> fun11 = new Func<string, bool>(fun);
//第三Func委托类型的一个委托变量,让其已经指向一个匿名函数函数
//Func<string, bool> fun11 = delegate(string str)
//{
// if (str.Contains("aa"))
// {
// return true;
// }
// else
// return false;
//};
//第四Func委托类型的一个委托变量=一个函数。
Func<string, bool> fun11=fun;
IEnumerable<string> temp = list.Where<string>(fun11);
foreach (var item in temp)
{
Console.WriteLine(item);
}
Console.ReadKey(); //Where Find OrderBy Take Skip
//var res = list.Find(a => a.Equals("aa"));
//int[] arr = { 1, 2, 3 };
}
}
}

Where Find OrderBy Take Skip用到的泛型委托方法。Func的来龙去脉

T2 Func<in T1,out T2>(T1 arg)的更多相关文章

  1. 现在有T1、T2、T3三个线程,怎样保证T2在T1执行完后执行,T3在T2执行完后执行?使用Join

    public class TestJoin { public static void main(String[] args) { Thread t1 = new Thread(new T1(), &q ...

  2. 【测试】在hr用户下自行创建T1和T2表写一条SQL语句,(NL连接)

    SQL> select t1.* from t1,t2 where t1.object_id=t2.object_id; rows selected. Execution Plan ------ ...

  3. MRI中T1和T2的含义与区分[转]

    A. MRI名词解释   T1加权像.T2加权像为磁共振检查中报告中常提到的术语,很多非专业人士不明白是什么意思,要想认识何为T1加权像.T2加权像,请先了解几个基本概念:   1.磁共振(maget ...

  4. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group t1,customer t2

    ### SQL: select t1.gid,t1.gname,t1.gvalue,t1.gtype, t1.gaddress,t1.gmembers, t1.gcode,t1.gphone, t2. ...

  5. 查出了a表,然后对a表进行自查询,a表的别名t1,t2如同两张表,因为t1,t2查询的条件不一样,真的如同两张表,关联两张表,可以将两行或者多行数据合并成一行,不必使用wm_concat()函数。为了将t2表的数据全部查出来使用了右连接。

    with a as( select nsr.zgswj_dm, count(distinct nsr.djxh) cnt, 1 z from hx_fp.fp_ly fp, hx_dj.dj_nsrx ...

  6. T1,T2,T3 三个线程顺序执行

    T1,T2,T3 三个线程顺序执行 现在有 T1.T2.T3 三个线程,你怎样保证 T2 在 T1 执行完后执行,T3 在 T2 执行完后执行?(T1->T2->T3) 这个线程问题通常会 ...

  7. 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?

    Thread t1 = new Thread(new T1()); Thread t2 = new Thread(new T2()); Thread t3 = new Thread(new T3()) ...

  8. T1加权像(T1 weighted image,T1WI)

    T1加权成像(T1-weighted imaging,T1WI)是指这种成像方法重点突出组织纵向弛豫差别,而尽量减少组织其他特性如横向弛豫等对图像的影响. 弛豫:物理用语,从某一个状态恢复到平衡态的过 ...

  9. Day2:T1搜索 T2最小生成树

    T1:广搜+判断矩形 注:如何判断搜的是否为矩形: 在广搜的时候,记录下边界的坐标,然后枚举一遍过去,如果搜到"."就是牛群,否则就是房间 瞥了一眼ccy的做法,据说是floodf ...

随机推荐

  1. 自写网站入门阶段之三:兼容大战与jq初探

    自上一次作小结至今已整整一个月,在忙乎了半个月的工作之后闲下来的一个下午我终于可以再次作这个阶段的小结了.首先庆幸的是在同学的推荐下我顺利的找到了工作并于月初3号正式上班,这一点非常感谢他,让我免去了 ...

  2. .NET导入导出Excel方法总结

    最近,应项目的需求,需要实现Excel的导入导出功能,对于Web架构的Excel导入导出功能,比较传统的实现方式是: 1)导入Excel:将Excel文件上传到服务器的某一文件夹下,然后在服务端完成E ...

  3. 多重网格法简介(Multi Grid)

    原文链接 多重网格法是一种用于求解方程组的方法,可用于插值.解微分方程等. 从专业角度讲多重网格法实际上是一种多分辨率的算法,由于直接在高分辨率(用于求解的间隔小)上进行求解时对于低频部分收敛较慢,与 ...

  4. MapReduce的核心资料索引 [转]

    转自http://prinx.blog.163.com/blog/static/190115275201211128513868/和http://www.cnblogs.com/jie46583173 ...

  5. Eclipse 设置SVN忽略文件

    1.在 Eclipse 中点击菜单 window --> Preferences --> Team --> Ignored Resources 2.在Eclipse的导航视图中,选中 ...

  6. JavaScript高级程序设计学习笔记--错误处理与调试

    try-catch语句 只要代码中包含finally子句,则无论try或catch语句块中包含什么代码--甚至return语句,都不会阻止finally子句的执行,来看下面这个函数: function ...

  7. [python面向对象]--基础篇

    1.#类 #类就是一个模板,模板里可以包含多个函数,函数里实现一些功能 #定义一个类 class bar: def foo(self,agr): print(self,agr) obj = bar() ...

  8. SQL查询语句行转列横向显示

    http://blog.163.com/dreamman_yx/blog/static/26526894201121595846270/

  9. LoadRunner 参数和变量的区别(未完)

    挺久没来更新了,坚持是件不容易的事呢,之后坚持每天总结下前一天的学习点 在LR中,参数是一种更高级的变量,他们能起到同样的效果,但同时也有几点不同 1. 定义方法不同 (这个还没看懂) 2. 调用语法 ...

  10. psql-09表:视图和索引

    视图 由查询语句定义的虚拟表;从视图中看到的数据可能来自数据库中的一张或多张表,也可能来自外部; 使用视图的原因一般有: 使复制的查询易于理解和使用; 安全原因; 表一些函数返回的结果映射成视图; 一 ...