How to avoid a string reference for Invoke()

Avoiding a (direct) string reference to a method name is actually fairly easy to do:

        // Once the disco music is finished, turn back to the fight music loop
        Invoke(nameof(FightMusic), soundLength);

So, Invoke() will still get a string, but it’s not a manually typed one and therefore fairly safe against typos.
Of course it does not protect against accidentally chosing a different method than we wanted to use…

1 Like

Privacy & Terms