C # delegates and C-language function pointers and array of function pointers
When using C # There is always a doubt about the delegate, but now it's always a new review of the C language to really understand the delegate.
In fact, a delegate is similar to a function pointer in c/s + +, which passes the function pointer when the function is passed, and accesses the function through a pointer when called.
The declaration of a function pointer in the C language is as follows:
It can be understood that a pointing variable Func, whose type is a parameter that returns type (which can be void), is received (Type One,type,...) Type of
Parameter (parameters can not be accepted). * Func(Type one,type,...)
In the C language, the function pointer array is declared as follows:
//Similar to the above understanding, declare an array of func pointers, whose length is num, which is of type int () (Type One,type,...) Type (*func[num]) (type One,type,,...)
Passed as a parameter in a function:
When using function TestFunc, you need to pass a function that has the same type declaration (type () (type One,type two,...)).
Can make the function more flexible, and can pass in the corresponding function according to the specific requirement to increase the reusability of the code. type TestFunc (Type value1,type value2,type *Func (type One,type,,...)) { Func (value1,value2,...);}
Although there is no pointer in C # (actually), it is useful to understand the concept and usage of pointers in C #.
C # delegates and C-language function pointers and array of function pointers