I see delegates in two forms:
A. Func<string, string> convertMethod = lambda
B. public delegate string convertMethod(string value);
I’m uncertain of what actually the difference between these two are. Are they both delegates? I believe the first one would use a lambda and the second would have to have a method to actually perform the work. I may be confused too.
First of all, your two examples are doing two totally separate things. The first is declaring a generic delegate variable and assigning a value to it, the second is just defining a
delegatetype. Your example, more completely, would be:But more to the point, both
Func<string,string>anddelegate string convertMethod(string)would be capable of holding the same method definitions whether they be methods, anonymous methods, or lambda expressions.As for which you should use, depends on the situation. If you want your delegate to be defined more by what it takes and returns, then the generic delegates are perfect. If you want the delegate to have some special name that gives more definition of what that delegate should do (beyond simple
Action,Predicate, etc) then creating your own delegate is always an option.