re help with array of functions more info

G

Guest

Hi,
I hope the following makes it clearer what I am trying to do.

lets say I have 3 methods

private int method1()
{

}


private int method2()
{

}


private int method3()
{

}


How can I code the following
setup the array

method [] ArrayMethod = { method1,method2,method3 };

and call by
x=method[2];

Many thanks.
 
J

Jon Skeet [C# MVP]

I hope the following makes it clearer what I am trying to do.

lets say I have 3 methods

private int method1()
{

}


private int method2()
{

}


private int method3()
{

}


How can I code the following
setup the array

method [] ArrayMethod = { method1,method2,method3 };

and call by
x=method[2];

You would do:

delegate int IntMethod();

IntMethod[] methods = new IntMethod[]{new IntMethod(method1),
new IntMethod(method2),
new IntMethod(method3)};

int x = methods[2]();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top