Understanding parentheses – why are they there?
One thing for sure is that parentheses make it easy to recognize that it's a method, but why are they part of a method's name?
We already know that a method is a code block that is going to be called multiple times. That's one of the reasons a method is created in the first place—so that we don't have to write the same code over and over. Remember the AddAndPrintTwoNumbers()
example method? We have mentioned that a method can take some input parameters. Why is this useful?
A script may need to add two numbers several times, but they probably won't always be the same two numbers. We can have possibly hundreds of different combinations of two numbers to add together. This means that we need to let the method know which two numbers need to be added together at the moment when we call the method. Let's write a code example to make sure you fully understand it:
Lines 7, 8, and 9 should be quite clear to you—simple declarations of variables.
Let's take...