如何在C#2.0中重写lambda表达式?
这段代码是什么意思,我需要将这段代码从VS 2008移植到VS 2005,同样的代码在VS 2005中不可用,c#2.0支持如何在C#2.0中重写lambda表达式?,c#,C#,这段代码是什么意思,我需要将这段代码从VS 2008移植到VS 2005,同样的代码在VS 2005中不可用,c#2.0支持delegate关键字,因此可以将其改写为: MatchEvaluator evaluator = (match) => { var splitPos = match.Value.IndexOf("=\""); var newValue = match.Value.Substrin
delegate
关键字,因此可以将其改写为:
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;
};
这和这个完全一样:
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;
};
致电:
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;
}
这是什么
MSDN:表示每次在替换方法操作期间发现正则表达式匹配时调用的方法
var
也是仅限VS2008的-在VS2005中构建此项时,您需要将var
替换为实际类型,例如第一种情况下为int
,第二种情况下为string
(我认为)。
MatchEvaluator evaluator = OnEvaluator;