
Learning C# by Developing Games with Unity
By :

Methods have been a big part of our code since we learned how to use them in Chapter 3, Diving into Variables, Types, and Methods, but there are two intermediate use cases we haven’t covered yet: method overloading and using the ref
and out
parameter keywords.
The term method overloading refers to creating multiple methods with the same name but with different signatures. A method’s signature is made up of its name and parameters, which is how the C# compiler recognizes it. Take the following method as an example:
public bool AttackEnemy(int damage) {}
The method signature of AttackEnemy()
is written as follows:
AttackEnemy(int)
Now that we know the signature of AttackEnemy()
, it can be overloaded by changing the number of parameters or the parameter types themselves, while still keeping its name. This provides added flexibility when you need more than one option for a given operation.
The RestartLevel...