Language question

S

Sagaert Johan

Is it possible to do something like this ?
string methodtoexecute="GetCount";

myclass.methodtoexecute();


now i solve it using a switch construct like this :

switch(methodtoexecute)
{
case "GetCount":
i=myclass.GetCount();
break;
case "GetRunTime":
i=myclass.GetRunTime();
default:
break;
}

Johan
 
J

Jon Skeet [C# MVP]

Sagaert Johan said:
Is it possible to do something like this ?
string methodtoexecute="GetCount";

myclass.methodtoexecute();

Not quite like that, but using reflection you can do basically the same
thing. Look at Type.GetMethod, and MethodBase.Invoke for more
information.
 

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