I'm converting code from C++ to C#. I have this line:
typedef bool (*proc)(int*, ...);
Can I do that in C#?
A typedef, or a function-type alias, helps to define pointers to executable code within memory. Simply put, a typedef can be used as a pointer that references a function.
You can declare any type with typedef , including pointer, function, and array types. You can declare a typedef name for a pointer to a structure or union type before you define the structure or union type, as long as the definition has the same visibility as the declaration.
Short answer: Yes.
Generally:
(untested... just an outline)
{
bool AFunction(ref int x, params object[] list)
{
/* Some Body */
}
public delegate bool Proc(ref int x, params object[] list); // Declare the type of the "function pointer" (in C terms)
public Proc my_proc; // Actually make a reference to a function.
my_proc = AFunction; // Assign my_proc to reference your function.
my_proc(ref index, a, b, c); // Actually call it.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With