Question

This question may sound trivial, but let me ask it nevertheless.

I found on the Internet the following example of calling an anonymous method using Invoke in VB.NET:

Invoke(New MethodInvoker(Sub() SomeMethod(param1)))

But why not call it this way, which looks cleaner? Is there any difference?

Invoke(Sub() SomeMethod(param1))
Était-ce utile?

La solution

Just to conclude and close the topic. Based on the comments, both the examples of Invoke calls are correct, but the one using MethodInvoker instantiation is faster, because no extra typecasting has to be performed at runtime, as MrPaulch stated.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top