我有 UserControl 命名例如'aaa'
然后我有变量:
Dim a as String = "aaa"
现在,我声明
Dim uc as UserControl = new aaa
我的问题是,我可以使用下面的变量值在上面写声明吗
Dim uc as UserControl = new a
我有 UserControl 命名例如'aaa'
然后我有变量:
Dim a as String = "aaa"
现在,我声明
Dim uc as UserControl = new aaa
我的问题是,我可以使用下面的变量值在上面写声明吗
Dim uc as UserControl = new a
您可以使用反射(在System.Reflection
)命名空间中执行此操作。例如:
Dim t As Type = Assembly.GetExecutingAssembly().GetType("namespace.aaa")
Dim o As Object = Activator.CreateInstance(t)
请注意,您将需要完整的类型名称,包括命名空间,因此您可能需要将其连接到您的字符串,例如:
Dim namespace As String = "MyNamespace"
Dim t As Type = Assembly.GetExecutingAssembly().GetType(namespace & "." & a)
Dim o As Object = Activator.CreateInstance(t)