5
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

Marc Gravell
1.1m273 gold badges2.6k silver badges3k bronze badges
asked Apr 11, 2011 at 10:23

1 Answer 1

9

c# 2.0 supports the delegate keyword, so it could be rewritten into this:

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.

http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator.aspx

answered Apr 11, 2011 at 10:26
Sign up to request clarification or add additional context in comments.

1 Comment

var is also VS2008 only - when building this in VS2005 you will need to replace var with the actual type, e.g. int in the first case and string in the second (I think).

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.