[英]How do I rewrite a lambda expression in C# 2.0?
MatchEvaluator evaluator = (match) =>
{
var splitPos = match.Value.IndexOf("=\"");
var newValue = match.Value.Substring(0, splitPos + 2) +
"RetrieveBuildFile.aspx?file=" +
prefix +
match.Value.Substring(splitPos + 2);
return newValue;
};
What does this code mean , I need to port this code which is in VS 2008 to VS 2005, the same is not available in VS 2005 这段代码意味着什么,我需要将VS 2008中的这段代码移植到VS 2005,VS 2005中也没有
c# 2.0 supports the delegate
keyword, so it could be rewritten into this: c#2.0支持delegate
关键字,因此可以将其重写为:
MatchEvaluator evaluator = delegate(Match match) {
int splitPos = match.Value.IndexOf("=\"");
string newValue = match.Value.Substring(0, splitPos + 2) +
"RetrieveBuildFile.aspx?file=" +
prefix +
match.Value.Substring(splitPos + 2);
return newValue;
};
And this is exactly the same as this: 这与此完全相同:
static string OnEvaluator(Match match) {
int splitPos = match.Value.IndexOf("=\"");
string newValue = match.Value.Substring(0, splitPos + 2) +
"RetrieveBuildFile.aspx?file=" +
prefix +
match.Value.Substring(splitPos + 2);
return newValue;
}
called with: 叫来:
MatchEvaluator evaluator = OnEvaluator;
And what it is? 它是什么?
MSDN: Represents the method that is called each time a regular expression match is found during a Replace method operation. MSDN:表示每次在Replace方法操作期间找到正则表达式匹配时调用的方法。
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator.aspx http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.