Methods Revisited Quiz
Below are the answers to the Methods Revisited Quiz, along with a brief discussion.
1. y
and z
are optional, because they use =
to assign a default value.
2. x=1, y=2, z=4. The value passed in goes to x
, while y
and z
take on their default values.
3. x=2, y=3, z=9. x
and z
are both assigned a value with named parameters, while y
takes on its default value.
4. True.
5. True.
6a. Not allowed because no parameter is available to go into the x
variable.
6b. Allowed. The 1 goes into the x
variable and the numbers
array is empty.
6c. Allowed. The 1 goes into the x
variable and the numbers
array contains [2, 3, 4, 5].
6d. Allowed. The 1 goes into the x
variable and the numbers
array takes on the value passed in.
7. True. When you use out
or ref
, the receiving method ends up with access to the actual original variable.
8. True. (See #7.)
9. True. out
requires that the called method assign a value to the variable. It is considered an output parameter.
10. False. With ref
, it is expected that the calling method assigns a value to the variable. The called method can assume that it was already initialized.