I assume that your question is about C #, not .NET, because of the ambiguity of your question, since .NET does not get lonely - that is, without C # - understanding delegates and lambda expressions.
A (normal, as opposed to the so-called common delegates, cf later), the delegate should be considered as a kind of C ++ typedef type of function pointer, for example, in C ++:
R (*thefunctionpointer) ( T ) ;
typedef type thefunctionpointer , which is a type of function pointer that takes an object of type T and returns an object of type R You would use it as follows:
thefunctionpointer = &thefunction ; R r = (*thefunctionpointer) ( t ) ; // where t is of type T
where thefunction will be a function that takes T and returns R
In C # you will go for
delegate R thedelegate( T t ) ;
and you will use it as follows:
thedelegate thedel = thefunction ; R r = thedel ( t ) ; // where t is of type T
where thefunction will be a function that takes T and returns R This is for delegates, the so-called normal delegates.
Now you also have common delegates in C # that are delegates that are common, that is, "templates", so to speak, using a C ++ expression. They are defined as follows:
public delegate TResult Func<in T, out TResult>(T arg);
And you can use them as follows:
Func<double, double> thefunctor = thefunction2;
where thefunction2 is a function that takes as an argument and returns a double .
Now imagine that instead of thefunction2 I would like to use a “function”, which is not yet defined, using an instruction, and that I will never use it later. Then C # allows you to use the expression of this function. By expression I mean the expression "mathematical" (or functional to stick with programs), for example: before double x I will contact double x*x . In math, you write this using the "\ mapsto" latex character . Functional notation was written in C #: => . For example:
Func<double, double> thefunctor = ( (double x) => x * x );
(double x) => x * x is expression . This is not a type, while delegates (general or not).
Morality? After all, what is a delegate (or generic delegate) if not a function pointer type (e.g. wrapped + smart + generic function pointer type), yes? Something other! See
this and
which .