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 ...
随机推荐
- javascript数据结构-队列
gihub博客地址 队列(Queue)是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表.进行插 ...
- jquery.roundabout.js图片叠加3D旋转插件多功能图片翻转切换效果
http://www.17sucai.com/pins/4880.html DEMO演示地址:http://www.17sucai.com/pins/demoshow/4880
- How do I enable log4net internal debugging?
http://logging.apache.org/log4net/release/faq.html
- setTimeout和setInterval的注意事项
精准问题 setTimeout的问题在于它并不是精准的,例如使用setTimeout设定一个任务在10ms后执行,但是在9ms后,有一个任务占用了5ms的cpu时间片,再次轮到定时器执行时,时间已经过 ...
- maven install 构建报错(2)
错误:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin: 2.3 . 2 :compile ( default ...
- Sass中文乱码问题(手动编译和watch编译)
一.sass手动编译出错 .scss文件中含有中文的时候编译报错(比如注释,比如字体栈),比如: foo.scss: 编译: 解决办法: 找到类似这个的路径的文件(仅供参考,不同环境可能不同): C: ...
- Java如何保存含有时间的日期到Oracle数据库
原文:http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01 从Oracle ...
- Maven 更换远程仓库地址
1.第一种方式,通过setting.xml的方式配置数据源 该文件路径D:\IDE\apache-maven-3.2.3\conf\setting.xml 该文件大部分内容都已经注释,我们需要添加如下 ...
- UC浏览器 分享到朋友圈和微信好友 分类: JavaScript 2015-04-28 14:45 615人阅读 评论(1) 收藏
用手机UC浏览器访问新浪微博,会注意到有这样的两个分享按钮: 在手机端浏览器里,点击分享按钮,就可以启动微信客户端并分享到微信.研究了下其源代码,存在这样的一个js:http://mjs.sinaim ...
- Monitoring Processes with Supervisord
If you're interested in more of this type of content, check out the Servers for Hackers eBook! As so ...