void func(void (*func2)());
C# question
In C++ you can have function pointers as arguements using a declaration like
Is there similar functionality in C#?
Delegates.
(untested)
delegate void IntMethod(int value);// ...void JustPrintIt(int value){ Console.WriteLine(value);}void CallFunction(IntMethod method, int value){ method(value);}// ...CallFunction(JustPrintIt, value);
(untested)
Yes, they are called delegates and look like:
So, in your case:
Skizz
access delegate return_type DelgateName (function parameters);
So, in your case:
public delegate void Func2 ();public void Func (Func2 func2){}
Skizz
Yes, delegates are the way to this in C# however you should be aware that delegates are more than just function pointers.
A few extras to note:
Delegates are classes; they have methods and properties
Delegates can point to multiple functions (multicast delegates)
Delegates have built-in support for asynchronous calls.
When trying to implement properties of delegates, consider using events. Events are 'ecapsulated' delegate properties.
A few extras to note:
Delegates are classes; they have methods and properties
Delegates can point to multiple functions (multicast delegates)
Delegates have built-in support for asynchronous calls.
When trying to implement properties of delegates, consider using events. Events are 'ecapsulated' delegate properties.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement