views:

59

answers:

2

Hi guys

I want to create an instance of a type that I specify in a generic method that I have. This type has a number of overloaded constructors. I'd like to be able to pass arguments to the constructors, but

Activator.CreateInstance<T>()

doesn't see to have this as an option.

Is there another way to do it?

Thanks

Dave

+4  A: 

Yes.

(T)Activator.CreateInstance(typeof(T), param1, param2);
SLaks
A: 

You can also not use Activator.CreateInstance and could preform better than Activator. See StackOverflow post:

http://stackoverflow.com/questions/2024435/how-to-pass-ctor-args-in-activator-createinstance

thames