call a function from a string variable

BitFiddler

New member
Joined
Mar 20, 2021
Messages
2
Programming Experience
10+
Hello, very new to c# so i am not sure what all the terminology is to ask this question properly, so bear with me.

ok first assume i have a function made:

void someFunction()
{
//do stuff

}



now in "main" i want to call this function so i set up a string variable to contain the function name:

str funcName = "someFunction()";

how do i then call this function? in psudocode it may read:

call(funcName);

or something of this nature. Is this possible and if so how?
 
Read about "reflection".
 
There are good reasons to use Reflection at times but people are often misguided in trying to do this sort of thing. What is your reason for wanting to do so? If it's just to learn something then that's fine, but be aware that valid uses for Reflection come up infrequently. If you think that you actually need it for a particular application, I'd be interested to know exactly why because, in my experience, there are generally better options.
 
Back
Top Bottom