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 ...
随机推荐
- POJ2195 最小费用流
题目:http://poj.org/problem?id=2195 处理出每个人到每个门的曼哈顿距离,分别建立容量为1费用为曼哈顿距离的边,在源点和每个人人之间建立容量为1费用为0的边,在门和汇点之间 ...
- java基础 作业(一)
题目: 跳水比赛,8个评委打分.运动员的成绩是8个成绩去掉一个最高分,去掉一个最低分,剩下的6个分数 的平均分就是最后 得分.使用以为数组实现打分功能 .请把打分最高的评委和最低的评委找出来. 解析: ...
- GitHub使用教程
一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等一系列工具进行Copy,然后回家才能继续在原来的基础上作业.Cop ...
- python function parameter
Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...
- Python里*arg 和**kwargs的作用
Hi,伙计们.我发现Python新手们在理解*args和**kwargs这两个魔法变量时都有些困难.他们到底是什么?首先,我先告诉大家一个事实,完整地写*args和**kwargs是不必要的,我们可以 ...
- Python dir
1. 在python命令行交互环境下,可以用dir()函数查看当前的变量,比如: >>> dir()['__builtins__', '__doc__', '__loader__', ...
- W7无法更新
从提示中可以推断可能服务中没有启动更新服务,当即开始>>>运行>>>services.msc 打开服务管理,找到Windows Update服务,启动它.重新更新服 ...
- iOS 获取沙盒路径方法
//获取家目录路径的函数: NSString *homeDir = NSHomeDirectory(); //获取Documents目录路径的方法: NSArray *paths = NSSearch ...
- js 获取元素宽高
可以用源生js的.offsetHeight .offsetWidth属性 document.getElementById("temp_form").offsetHeight // ...
- 【django】京东等大型网站的混合搜索是怎么实现的?
混合搜索在各大网站如京东.淘宝都有应用,他们的原理都是什么呢?本博文将为你介绍它们的实现过程. 混合搜索的原理,用一句话来说就是:关键字id进行拼接. 混合搜索示例: 数据库设计: 视频方向: cla ...