Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#2.0中重写lambda表达式?_C# - Fatal编程技术网

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

如何在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

这段代码是什么意思,我需要将这段代码从VS 2008移植到VS 2005,同样的代码在VS 2005中不可用,c#2.0支持
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;