Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C# equivalent of CallByName?

811 views
Skip to first unread message

Lynn Kear-Noe

unread,
May 20, 2003, 3:31:56 PM5/20/03
to
I want to store a method name as a string in my
datatable, and at runtime retrieve the string and use it
to call the method. It looks like VB's CallByName method
does this. Is there an equivalent in C#?

Thanks,
Lynn

Alex Feinman [MVP]

unread,
May 20, 2003, 3:38:30 PM5/20/03
to
This assumes, that the method is public and is not overloaded.

using System.Reflection;

object o; // Your object on which you are calling the method
MethodInfo mi = o.GetType().GetMethod(methodname);
object[] Params = new object[] { <parameters go here> };
object retval = mi.Invoke(o, Params);

"Lynn Kear-Noe" <Lynn.K...@mt.com> wrote in message
news:03ea01c31f06$7954a0c0$a301...@phx.gbl...

Lynn Kear-Noe

unread,
May 20, 2003, 3:52:46 PM5/20/03
to
Thank you for the quick response!

Lynn

>.
>

0 new messages