Hello everyone,
There are two ways to use reflection to invoke a method,
1. Using InvokeMember;
2. Using GetType.GetMethod to retrieve a MethodInfo object, then use the MethodInfo object to invoke the method.
My point is from the result point of view, they are the same, but method 2 if more efficient if we want to invoke the method multiple of times by the same MethodInfo object -- since each time we call InvokeMember, it needs to find the method, nothing saved as MethodInfo object in method 2 and each time InvokeMember did the binding to find the same method.
My question is whether my point of understanding is correct and whether there any more differences/pros/cons compared with the 2 methods.
thanks in advance,
George
Bechir BejaouiRank #144 · 15.9K pointsPosted Sep 8, 2008, 9:48 AM EDT
create a class and within it impelment the two method 1 and 2 then foreach method do impelement a counter this counts the execution duration to make the measure
George GeorgeRank #2,261 · 618 pointsPosted Sep 8, 2008, 10:07 PM EDT
My question is not asking which one is faster, but why faster? Any comments? :-)
regards,
George