0
Explain Delegates in detail
2 Respuestas
+ 1
Delegate usually accepts your output from a function/lambda and delegates that as input to your 'delegate' function, it's sort of precedence, do this then from that i delegate you to do the following... where the following is what your delegate method does...
0
https://msdn.microsoft.com/de-de/library/900fyy8e.aspx
Think of them like a reference type. a variable of a reference type just points to the memory, where the values are stored. But instead the delegate points to another method. The compiler needs to know, that you want to point to a method, not to an object. That's why you have to declare them with a basic structure like:
delegate double MathAction(double num);
Now you either provide a normal function like:
static double Double(double input) {
return input * 2;
}
and now assign it to an instance of the delegate type with:
MathAction ma = Double;
or you can just assign an anonymous function to the delegate (which has the great advantage of using local variables!):
MathAction ma2 = delegate(double input) {
return input * input;
};