我知道在php中你可以拨打电话:
$function_name = 'hello';
$function_name();
function hello() { echo 'hello'; }
Run Code Online (Sandbox Code Playgroud)
这可能在.Net吗?
可能重复:
如何使用其名称调用方法?
厌倦了使用switch/case语句.我想知道是否有某种方法可以根据用户提供的值调用方法.明白为什么这是一个坏主意可能有一百万个理由,但这就是我在想的:
Console.Write("What method do you want to call? ");
string method_name = Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
然后以某种方式调用'method_name'中包含的方法.这甚至可能吗?