Home > Backend Development > C++ > Can C# Call a Function from a String Using Reflection?

Can C# Call a Function from a String Using Reflection?

Patricia Arquette
Release: 2025-01-26 02:26:09
Original
886 people have browsed it

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?
$function_name = 'hello';
$function_name();

function hello() { echo 'hello'; }
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template