Re: re help with array of functions more info

Tech-Archive recommends: Fix windows errors by optimizing your registry



<CobraStrikes@xxxxxx> wrote:
> 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]();

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Raise event inside a thread
    ... using monitors or a ManualResetEvent. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: get the actual size of a file
    ... saying for certain either way:) ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading/Locking
    ... Then you stash the data in an ordered list which is then processed by ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to trigger other thread
    ... updates are "seen" or not. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: MemoryStream.Write() Offset cannot be zero
    ... a file - it's just like that, except it all stays in memory. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.framework)