473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help with array of functions

Hi All,

How can I create an array of functionsand how would I call them

many thanks
Nov 17 '05 #1
2 9012
mdb
<Co**********@al.com> wrote in news:d6**********@newsg2.svr.pol.co.uk:
How can I create an array of functionsand how would I call them


Look into delegates, and the Invoke() function.

-mdb
Nov 17 '05 #2
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


"Co**********@al.com" wrote:
Hi All,

How can I create an array of functionsand how would I call them

many thanks

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
9
by: kbc | last post by:
Hi, I am programming in C. ( You know that __FILE__ is a 'macro' which may be used to print debug messages. ) 3 questions : a) I have 10000 functions in my project. I am...
39
by: gtippery | last post by:
Newbie-ish questions - I've been away from C for a _long_ time. It seems to me that there ought to be easier (or at least shorter) ways to do what this does. It does compile & run for me (with...
1
by: john_g83 | last post by:
Hello all, new user to c programming and am having difficulty with a little program I am trying to write. Basically what I have is a file which contains a list of words i.e: tst.txt: customer...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
3
by: c++dummy | last post by:
I got this project for my class and I'm totally lost as to how to copy the 1d array with the bone name into a 2d array using this supposed strncpy function I'm supposed to create. I believe the...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
10
by: kickioly | last post by:
Hi everyone, this is my first time here and i hope it will not be the last, i have a problem here solving this C++ problem,and i hope that someone here to solve it and i'll be happy if you do it...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.