I came across a line of code that i can’t seem to grasp
Let me explain a little.
What i do understand is that with the following line i am defining a type of delegate with the name “myDelegate”. This type can hold a pointer to a function with signature int (int, int)
public delegate int myDelegate(int a, int b);
What i do not get is the following line:
public delegate T Func<T>(T a, T b);
I mean why would i define a type called Func which is already defined in the .NET framework ?
Well, it certainly seems like a bad idea to declare your own delegate when one with the same name and number of generic type parameters is available in the framework – but it’s not invalid. I suggest that if this is code you own, you rename it appropriately. Note that it’s not the same as
Func<T>as it’s usingTfor both inputs and the output. You might want to call itBinaryOperatoror something similar (although binary operators don’t have to have the same operand types, nor does the return value have to be of the same type).