DaveDev DaveDev - 1 year ago 91
C# Question

How to Pass Parameters to Activator.CreateInstance<T>()

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


doesn't see to have this as an option.

Is there another way to do it?

Answer Source


(T)Activator.CreateInstance(typeof(T), param1, param2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download