Home >Backend Development >C++ >Can C# Call a Function from a String Using Reflection?
In the string call function
PHP can call the function through the string, as shown below:
.NET could achieve similar functions?
<code class="language-php">$function_name = 'hello'; $function_name(); function hello() { echo 'hello'; }</code>
Answer:
Yes, .NET can use the reflection string to call the function. The following is the implementation method:
In the above code, the method of calling must have a public access decoration. If you need to call the non -public method, you can use the bindingflags parameter, as shown below:
The above is the detailed content of Can C# Call a Function from a String Using Reflection?. For more information, please follow other related articles on the PHP Chinese website!