2

I have UserControl named for example 'aaa'

then i have variable:

Dim a as String = "aaa"

Now, i declare

Dim uc as UserControl = new aaa

my question is, can i write declaration above using value of variable a like below

Dim uc as UserControl = new a

1 Answer 1

1

You can do this using reflection (in the System.Reflection) namespace. For instance:

Dim t As Type = Assembly.GetExecutingAssembly().GetType("namespace.aaa")
Dim o As Object = Activator.CreateInstance(t)

Notice that you will need the full type name, including the namespace, so you may need to concatenate that to your string, for instance:

Dim namespace As String = "MyNamespace"
Dim t As Type = Assembly.GetExecutingAssembly().GetType(namespace & "." & a)
Dim o As Object = Activator.CreateInstance(t)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.