Hi,

How can I send a method as a parameter to be executed in a class?
If possible without using delegate.

public void MethodA()
{
// Code
}

public void ExecuteMethod( * MethodParam )
{
// Invoke the method parameter
**MethodParam.invoke();
}

public void main()
{
// Call ExecuteMethod sending MethodA as a parameter
ExecuteMethod( * MethodA );
}

Re: Sending a method as a parameter by Lau

Lau
Thu Jan 12 04:28:33 CST 2006

That's what delegate function is invented for. :)

You can assign a function PROTOTYPE as parameter, and accept a function that
"accept that kind of parameter" as parameter. (not intented pun)

"Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
¼¶¼g©ó¶l¥ó·s»D:40FD71A9-D274-4727-A074-D0DE24C4DE56@microsoft.com...
> Hi,
>
> How can I send a method as a parameter to be executed in a class?
> If possible without using delegate.
>
> public void MethodA()
> {
> // Code
> }
>
> public void ExecuteMethod( * MethodParam )
> {
> // Invoke the method parameter
> **MethodParam.invoke();
> }
>
> public void main()
> {
> // Call ExecuteMethod sending MethodA as a parameter
> ExecuteMethod( * MethodA );
> }
>



Re: Sending a method as a parameter by Lau

Lau
Thu Jan 12 04:31:50 CST 2006

Ar, I overlooked the question...

If it's C/C++, there's a type of function called CALLBACK function. (The
WinProc in Classic C-style Windows program is an obvious one)

But I think that's similar to delegate anyway(delegate is invented to get
rid of pointers I believe).

"Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
¼¶¼g©ó¶l¥ó·s»D:40FD71A9-D274-4727-A074-D0DE24C4DE56@microsoft.com...
> Hi,
>
> How can I send a method as a parameter to be executed in a class?
> If possible without using delegate.
>
> public void MethodA()
> {
> // Code
> }
>
> public void ExecuteMethod( * MethodParam )
> {
> // Invoke the method parameter
> **MethodParam.invoke();
> }
>
> public void main()
> {
> // Call ExecuteMethod sending MethodA as a parameter
> ExecuteMethod( * MethodA );
> }
>



Re: Sending a method as a parameter by RobyEisenbraunMartins

RobyEisenbraunMartins
Thu Jan 12 04:40:03 CST 2006

Sorry about the missing information.
I talking about NET2005 C#.
I could you explain it a little more? What do you mean by that?
Maybe a sample?

Thank you,
Roby Eisenbraun Martins

"Lau Lei Cheong" wrote:

> That's what delegate function is invented for. :)
>
> You can assign a function PROTOTYPE as parameter, and accept a function that
> "accept that kind of parameter" as parameter. (not intented pun)
>
> "Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
> ¼¶¼g©ó¶l¥ó·s»D:40FD71A9-D274-4727-A074-D0DE24C4DE56@microsoft.com...
> > Hi,
> >
> > How can I send a method as a parameter to be executed in a class?
> > If possible without using delegate.
> >
> > public void MethodA()
> > {
> > // Code
> > }
> >
> > public void ExecuteMethod( * MethodParam )
> > {
> > // Invoke the method parameter
> > **MethodParam.invoke();
> > }
> >
> > public void main()
> > {
> > // Call ExecuteMethod sending MethodA as a parameter
> > ExecuteMethod( * MethodA );
> > }
> >
>
>
>

Re: Sending a method as a parameter by Kevin

Kevin
Thu Jan 12 08:58:14 CST 2006

Hi Roby,

See:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefthedelegatetype.asp

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Roby Eisenbraun Martins" <RobyEisenbraunMartins@discussions.microsoft.com>
wrote in message news:771292F2-5EF4-4945-AFCC-8EB814A6C68B@microsoft.com...
> Sorry about the missing information.
> I talking about NET2005 C#.
> I could you explain it a little more? What do you mean by that?
> Maybe a sample?
>
> Thank you,
> Roby Eisenbraun Martins
>
> "Lau Lei Cheong" wrote:
>
>> That's what delegate function is invented for. :)
>>
>> You can assign a function PROTOTYPE as parameter, and accept a function
>> that
>> "accept that kind of parameter" as parameter. (not intented pun)
>>
>> "Roby Eisenbraun Martins"
>> <RobyEisenbraunMartins@discussions.microsoft.com>
>> ¼¶¼g©ó¶l¥ó·s»D:40FD71A9-D274-4727-A074-D0DE24C4DE56@microsoft.com...
>> > Hi,
>> >
>> > How can I send a method as a parameter to be executed in a class?
>> > If possible without using delegate.
>> >
>> > public void MethodA()
>> > {
>> > // Code
>> > }
>> >
>> > public void ExecuteMethod( * MethodParam )
>> > {
>> > // Invoke the method parameter
>> > **MethodParam.invoke();
>> > }
>> >
>> > public void main()
>> > {
>> > // Call ExecuteMethod sending MethodA as a parameter
>> > ExecuteMethod( * MethodA );
>> > }
>> >
>>
>>
>>