摘要:
在Action<Of T>基础上增加了返回值,其参数原型如下:publicdelegateTResultFunc<inT,outTResult>(Targ)/*InT此委托封装的方法的参数类型。该类型参数是逆变的。即可以使用指定的类型或派生程度更低的类型。有关协变和逆变的更多信息,请参见泛型中的协变和逆变。OutTResult此委托封装的方法的返回值类型。该类型参数是协变的。即可以使用指定的类型或派生程度更高的类型。有关协变和逆变的更多信息,请参见泛型中的协变和逆变。*/以前Delegate方法:usingSystem;usingSystem.Windows.Forms 阅读全文
posted @ 2011-11-28 17:22
一路前行
阅读(310)
评论(0)
推荐(0)
摘要:
该功能与Action情况基本类似,但增加了参数传入功能。用Delegate的代码:usingSystem;usingSystem.Windows.Forms;publicdelegatevoidDisplayMessage(stringmessage);publicclasstestTestDelegate{publicstaticvoidMain(){DisplayMessageshowMethod=DisplayToWindow;showMethod("ZHANGPS");}publicstaticvoidDisplayToWindow(stringstrName){M 阅读全文
posted @ 2011-11-28 17:18
一路前行
阅读(391)
评论(2)
推荐(0)
摘要:
Action:相当于一种无参数传递的委托,从Framework 3.5开始加如,简化了委托调用代码:Delegate原代码:usingSystem;usingSystem.Windows.Forms;publicdelegatevoidDisplayMessage();publicclasstestTestDelegate{publicstaticvoidMain(){ DisplayMessageshowMethod=DisplayToWindow();showMethod();}publicstaticvoidDisplayToWindow(){MessageBox.Show(" 阅读全文
posted @ 2011-11-28 16:55
一路前行
阅读(2420)
评论(0)
推荐(1)
摘要:
classSimpleLambda{staticvoidMain(){//Datasource.int[]scores={90,71,82,93,75,82};//ThecalltoCountforcesiterationofthesourceinthighScoreCount=scores.Where(n=>n>80).Count();Console.WriteLine("{0}scoresaregreaterthan80",highScoreCount);//Outputs:4scoresaregreaterthan80}} 阅读全文
posted @ 2011-11-28 16:07
一路前行
阅读(505)
评论(0)
推荐(0)
浙公网安备 33010602011771号