I saw several questions here in SO about how to get a delegate to create an object instead of using ConstructorInfo.Invoke .
Here is an example: Using a delegate to invoke the constructor .
I just want to know why? If it's performance, why is the delegate faster?
Update
I understand that when you create a delegate, you get rid of validation when reusing it. This is an increase in productivity.
But does this happen when the constructor is called through the delegate? Same as doing var a = new XXX() or something else?
Do ConstructorInfo.Invoke() do the same as new XXX() ? (Do not consider validation)
When using Activator.CreateInstance() do it in much the same way as Constructor.Invoke() (except for searching / type checking).
I think my question boils down to: Is it possible to create objects in different ways (for example, different IL instructions) or all mention methods using the same instructions (s), but with different types of checks before the actual creation?
source share