RE: help with array of functions

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



If you are attempting to use different functions withint he same array then:

1) Declare delegate types
2) declare array of delegate[] type - use: (Delegate[] abc = new
Delegate[n];) not to be confused with (delegate[] abc = new Delegate[n];)
3) i

delegate void testdelegate(int param);

class tclass
{
public void testfunction(int p)
{
}
}

Delegate[] abc = new Delegate[10];
for (int op_counter = 0; op_counter < abc.Length; op_counter++)
{
if (abc[op_counter] == null) continue;
// if you know the delegate type then just use a cast
((testdelegate)abc[op_counter])(0);
// if you dont know the type, then ether query or call
invoke and catch an error
abc[op_counter].DynamicInvoke(new object[] { op_counter });
// validate delegate is actually pointing to the method you
think it should be poiting to
// use reflection for that - which parameters you are
comparing is up to you

//(typeof(tclass).GetMethod("testfunctionname");
// abc[op_counter].Method <-- will give you method info just
as above

}


be careful with exceptions. Also remember, that dynamic invoke is quite slow
comparing to statically defined types. Remmeber that dynamicinvoke takes
object[] as a paramter, therefore any integer values will get boxed/unboxed
(read in - performance issues).

On a bright note, if implemented properly it works very well. I have
implemented expression parser this way...

- Arthur




"CobraStrikes@xxxxxx" wrote:

> Hi All,
>
> How can I create an array of functionsand how would I call them
>
> many thanks
>
>
>
.



Relevant Pages

  • Re: Create an Object from an Array Class
    ... I want to invoke a method that takes String[] object as parameter ... this is an array of java.lang.String's). ... create a class of the field type ...
    (comp.lang.java.programmer)
  • Re: Create an Object from an Array Class
    ... invoke(object, objparameters) methods from some Objects. ... I want to invoke a method that takes String[] object as parameter ... this is the internal representation of the class (it means that this is an array of java.lang.String's). ...
    (comp.lang.java.programmer)
  • Re: Writing a .txt file
    ... you already know how to output the values to stdout. ... invoke your program like this: ... pointer/size combo. ... my goal ist not to write the array in the file only ...
    (microsoft.public.vc.language)
  • RE: What is wrong?
    ... HTH ... "Andy Dorph" wrote: ... > When I invoke it, I get an array that is filled (determined with the IsArray ...
    (microsoft.public.excel.programming)