Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • So you never write a function definition for public delegate double Rounder(double value); then? I think that may have been one of the places I felt very stuck. Commented Sep 12, 2013 at 14:08
  • @medivh Writing out delegates explicitly is a bit of an artifact from C# 2.0 I think. You can use lambda syntax pretty much everywhere now, and use Func<T1, T2, ...> or Action<T1, T2, ...> objects to represent the types of functions you want to pass around Commented Sep 12, 2013 at 14:11
  • @medivh it can be confusing because people are generally fairly loose with terminology: the word "delegate" is used to refer both to the type (the signature that must be matched, sort of) and instances (the actual methods / lambdas that do the work), and there's also the specific framework type System.Delegate ! Commented Sep 12, 2013 at 14:15
  • 2
    @medivh Remember, action and func are delegates, they're just delegates that have been defined in the standard library with generics so you don't have to define them yourself, they are as: public delegate void Action<T>(T input) and there's another one public delegate void Action<T1, T2>(T1 input1, T2 input2) and so on, and actions are defined in the .NET framework as public delegate U Func<T,U>(T input) and so on. The lambda syntax is simply an expression syntax that the compiler converts into the standard action/func delegates. Commented Sep 12, 2013 at 15:00
  • @AakashM Thanks for this answer, it's helped to understand lambdas much better than the "you use them in LINQ and TPL" understanding that I had before! Commented Sep 12, 2013 at 15:11