将字符串转换为类名 [英] Convert a string to a class name
本文介绍了将字符串转换为类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
请帮助我.
我将字符串传递给其中该字符串实际上是类名的方法.
现在,我想将该字符串转换为一个类,以便可以动态调用该类中的函数.
传递的字符串是Dynamic.
我该如何解决这个问题....
请帮助我.....
Hello,
Please help me in this.
Im passing a string to a method where the string is actually a class name.
Now I want to cast that string into a class, so that I can call the function in that class dynamically.
The passing string is Dynamic.
how can I solve this issue.....
please help me.....
推荐答案
为此,您需要使用反射.
您可以使用Activator.CreateInstance
[
To do this, you use reflection.
You can useActivator.CreateInstance
[^].
E.g.var instance = Activator.CreateInstance("Assenbly",className);
这篇关于将字符串转换为类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文