dynamic-invoke

Difference Between Invoke and DynamicInvoke

那年仲夏 提交于 2019-11-26 05:57:22
问题 What is the difference between Invoke and DynamicInvoke in delegates? Please give me some code example which explain difference between that two methods. 回答1: When you have a delegate instance, you might know the exact type, or you might just know that it is a Delegate . If you know the exact type, you can use Invoke , which is very fast - everything is already pre-validated. For example: Func<int,int> twice = x => x * 2; int i = 3; int j = twice.Invoke(i); // or just: int j = twice(i);