T2 Func<in T1,out T2>(T1 arg)
委托调用方法的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)的更多相关文章
- 现在有T1、T2、T3三个线程,怎样保证T2在T1执行完后执行,T3在T2执行完后执行?使用Join
public class TestJoin { public static void main(String[] args) { Thread t1 = new Thread(new T1(), &q ...
- 【测试】在hr用户下自行创建T1和T2表写一条SQL语句,(NL连接)
SQL> select t1.* from t1,t2 where t1.object_id=t2.object_id; rows selected. Execution Plan ------ ...
- MRI中T1和T2的含义与区分[转]
A. MRI名词解释 T1加权像.T2加权像为磁共振检查中报告中常提到的术语,很多非专业人士不明白是什么意思,要想认识何为T1加权像.T2加权像,请先了解几个基本概念: 1.磁共振(maget ...
- 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. ...
- 查出了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 ...
- T1,T2,T3 三个线程顺序执行
T1,T2,T3 三个线程顺序执行 现在有 T1.T2.T3 三个线程,你怎样保证 T2 在 T1 执行完后执行,T3 在 T2 执行完后执行?(T1->T2->T3) 这个线程问题通常会 ...
- 现在有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()) ...
- T1加权像(T1 weighted image,T1WI)
T1加权成像(T1-weighted imaging,T1WI)是指这种成像方法重点突出组织纵向弛豫差别,而尽量减少组织其他特性如横向弛豫等对图像的影响. 弛豫:物理用语,从某一个状态恢复到平衡态的过 ...
- Day2:T1搜索 T2最小生成树
T1:广搜+判断矩形 注:如何判断搜的是否为矩形: 在广搜的时候,记录下边界的坐标,然后枚举一遍过去,如果搜到"."就是牛群,否则就是房间 瞥了一眼ccy的做法,据说是floodf ...
随机推荐
- Keepalived日志
默认日志存放在系统日志:/var/log/messages下 [root@lb01 /]# tail -f /var/log/messages Oct :: lb01 Keepalived_vrrp[ ...
- HTTP的报文与状态码
本文是<HTTP权威指南>的读书笔记 HTTP报文是简单的格式化数据块.每条报文都包含一条来自客户端的请求或一条来自服务器的响应.它们由三部分组成: 对报文进行描述的起始行(start l ...
- PHP array 操作函数
array_map 函数的介绍 将数组的每个单元使用回调函数格式: array_map(callback, array) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- 数组去重及数组的prototype原型
Array.prototype.check= function(){ for(var i=0;i<this.length;i++){ for(var j=i+1;j<this.length ...
- 医学CT图像特征提取算法(matlab实现)
本科毕设做的是医学CT图像特征提取方法研究,主要是肺部CT图像的特征提取.由于医学图像基本为灰度图像,因此我将特征主要分为三类:纹理特征,形态特征以及代数特征,每种特征都有对应的算法进行特征提取. 如 ...
- Unity3D LuaBundleLoader(基于cslua)
说明:异步加载lua的bundle,会优先加载cache目录下bundle(一般更新的资源都在cache下) using System; using UnityEngine; using System ...
- Java设计模式之行为型模式
行为型模式共11种:策略模式.模板方法模式.观察者模式.迭代子模式.责任链模式.命令模式.备忘录模式.状态模式.访问者模式.中介者模式.解释器模式. 策略模式:策略模式的决定权在用户,系统本身提供不同 ...
- 提额 APP
提额 APP 开始参与这个APP也是巧合,一个月之前,我还在忙于电信运营商的工作,上级就过来问我在之前公司有没有用过 html css js这些.在维库的时候,可是从前台到后台都是要全包的呀,因为项目 ...
- java 项目中几种O实体类的概念
经常会接触到vo,do,dto的概念,本文从领域建模中的实体划分和项目中的实际应用情况两个角度,对这几个概念进行简析. 得出的主要结论是:在项目应用中,vo对应于页面上需要显示的数据(表单),do对应 ...
- svn工具安装下载Tomcat源码以及导入eclipse
安装 1.svn下载地址 https://tortoisesvn.net/downloads.html 2.语言包下载 3.先安装svn,在直接安装语言包 4.桌面右键可以看到相关svn信息 下载To ...