Hi everybody
I want to know what does this code do, why do they put a delegate? please explain me the topics and concepts behind every word
Thanks :)
Converter<int, String> converter = new Converter<int, String>(delegate(int value){return Convert.ToString(value);});
Converter<int, String> converter = new Converter<int, String>(delegate(int value)
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

naura paxRank #2,843 · 502 reputationPosted Jun 26, 2009, 4:27 AM EDT
I guess it is an anynomous function call which is passed as parameter in
the constructor on Converts class.
The constructor requires you to pass a reference to a method defined by you that
contains the logic to convert Tinput value to Toutput value
as in Converts(TInput,TOutput).
The same thing can be achived by following code.
Converter<int, String> converter = new Converter<int, String>(chk);
// A new Function defintion that converts integer to string.
private string chk(int val)
{
return val.ToString();
}
delegate has been used to create an anonymous method so that you don't have to define a concrete function as above.
I hope i'm making some sense here.
Please respond and comment on my post. I would appreciate that
Angel Romero5 reputationPosted Jun 26, 2009, 5:59 AM EDT
I wanted to identify the concepts behind that code snippet, "Anonymous method" is a good clue to keep on reading
Thanks!