C # delegates and C-language function pointers and array of function pointers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.