从字符串在C#中调用函数 [英] Calling a function from a string in C#
本文介绍了从字符串在C#中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在PHP您可以拨打电话,如:
I know in php you are able to make a call like:
$function_name = 'hello';
$function_name();
function hello() { echo 'hello'; }
这是可能的。Net?
Is this possible in .Net?
推荐答案
是的。您可以使用反射。事情是这样的:
Yes. You can use reflection. Something like this:
Type thisType = this.GetType();
MethodInfo theMethod = thisType.GetMethod(TheCommandString);
theMethod.Invoke(this, userParameters);
这篇关于从字符串在C#中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文