efficient object creation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Activator.CreateInstance vs. CunstructorInfo.Invoke

- If I may use either of them, which one is more efficient?
- When is one preferred to the other?

Thank you.
 
Activator.CreateInstance vs. CunstructorInfo.Invoke

- If I may use either of them, which one is more efficient?
- When is one preferred to the other?

I'm too lazy to look it up right now, but IIRC what
Activator.CreateInstance does is to look up the appropriate
constructor and call Invoke on it.

So if you're going to create multiple objects or if you already have
the ConstructorInfo object, it's probably faster to manually Invoke
that (no need to look up the same constructor again). But if it's a
one time thing and you don't have a ConstructorInfo object I don't
think it matters much which one you choose.


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

Back
Top