Calling a function from a string in C#

前端 未结 6 1613
别那么骄傲
别那么骄傲 2020-11-22 11:41

I know in php you are able to make a call like:

$function_name = \'hello\';
$function_name();

function hello() { echo \'hello\'; }

Is this

6条回答
  •  清歌不尽
    2020-11-22 12:35

    Yes. You can use reflection. Something like this:

    Type thisType = this.GetType();
    MethodInfo theMethod = thisType.GetMethod(TheCommandString);
    theMethod.Invoke(this, userParameters);
    

提交回复
热议问题