Activator.CreateInstance

G

Guest

In the example below i create a new object which is of SqlParameter type.

SqlParameter sqlParameter = new SqlParameter();
object newObject = Activator.CreateInstance(sqlParameter.GetType(), false);

How can I do the same thing but from a string defining the type ie. the type
i need to create my new object in is displayed as a string... is there code
that could do this...
sting targetObject = "System.Data.SqlClient.SqlParameter"
object newObject = Activator.CreateInstance(targetObject.GetType(), false);

many thanks CR
 
M

Mattias Sjögren

How can I do the same thing but from a string defining the type ie. the type
i need to create my new object in is displayed as a string...

Check out System.Type.GetType or System.Reflection.Assembly.GetType.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top