Using Invoke with string - IntelliSense completion

Hello there! Rick has talked about how using the Invoke-Method is not his favorite, because it takes a string. IntelliSense has prompted me with the suggestion to use;

Invoke(nameof(HandleDefaultCollision), levelLoadDelay);

Is this a viable alternative to using string?

1 Like

This is not only viable but better. You cannot make a typo - the compiler will complain if you do - and if you rename the function using F2 (that will also rename the references for you), this will be included so you don’t have to go looking for strings that references the renamed function.

When the code is being compiled, this is replaced by the ‘name’ (hence nameof) of the function, so there is no performance cost because in the compiled code it is exactly the same as if you have used the string

4 Likes

Alrighty! Thanks then, IntelliSense for the Win!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms