请问一个通过字符串指定类型的方法
请教一个通过字符串指定类型的方法
请高手指教类型指定问题。
例如:
dim stype as string
stype= "myclass " 'myclass 是我自己定义的一个class
下面我想声明一个myclass类的对象,也就是通过字符串来指定变量类型。
请问该如何编码实现?
------解决方案--------------------
Type myType1 = Type.GetType( "myclass "); //这里命名要注意
object o = Activator.CreateInstance (myType1)
------解决方案--------------------
查看帮助文档中关于 "反射 "的主题~
------解决方案--------------------
Type.GetType(这里是全名,甚至用到强类名,包括版本号等)
自定义的,全名就可以了.
比如:
Dim t As DataBase
t = CType(System.Activator.CreateInstance( _
Type.GetType( "SimpleWorksApplication.DataBase ")), DataBase)
请高手指教类型指定问题。
例如:
dim stype as string
stype= "myclass " 'myclass 是我自己定义的一个class
下面我想声明一个myclass类的对象,也就是通过字符串来指定变量类型。
请问该如何编码实现?
------解决方案--------------------
Type myType1 = Type.GetType( "myclass "); //这里命名要注意
object o = Activator.CreateInstance (myType1)
------解决方案--------------------
查看帮助文档中关于 "反射 "的主题~
------解决方案--------------------
Type.GetType(这里是全名,甚至用到强类名,包括版本号等)
自定义的,全名就可以了.
比如:
Dim t As DataBase
t = CType(System.Activator.CreateInstance( _
Type.GetType( "SimpleWorksApplication.DataBase ")), DataBase)