当前位置: 首页 > 编程语言 > C#

如何在C#2.0中重写lambda表达式?分享

时间:2023-04-10 11:43:53 C#

C#2.0中如何重写lambda表达式?MatchEvaluatorevaluator=(match)=>{varsplitPos=match.Value.IndexOf("="");varnewValue=match.Value.Substring(0,splitPos+2)+"RetrieveBuildFile.aspx?file="+前缀+match.Value.Substring(splitPos+2);returnnewValue;};这段代码是什么意思,我需要将这段代码从VS2008移植到VS2005,而且VS2005word中没有c#2.0支持委托键,所以它可以重写为:MatchEvaluatorevaluator=delegate(Matchmatch){intsplitPos=match.Value.IndexOf("="");stringnewValue=match.Value.Substring(0,splitPos+2)+"RetrieveBuildFile.aspx?file="+prefix+match.Value.Substring(splitPos+2);返回新值;};这与此完全相同:staticstringOnEvaluator(Matchmatch){intsplitPos=match.Value.IndexOf("="");stringnewValue=match.Value.Substring(0,splitPos+2)+"RetrieveBuildFile.aspx?file="+prefix+match.Value.Substring(splitPos+2);returnnewValue;}call:MatchEvaluatorevaluator=OnEvaluator;是什么?MSDN:表示每次在Replace方法中运行中发现正则表达式匹配时调用的方法http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator.aspx以上是C#学习教程:HowtoRewriteinC#2.0lambda表达式?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: