Practice mode C#

Which rule applies to optional parameters in C#?

Correct answer D. They must come after all required parameters and have compile-time constant defaults

Explanation

Optional parameters are declared with a default value, such as int count = 10, and must follow every required parameter. The default must be a compile-time constant, a default(T) expression or new S() for a value type, because the value is copied into the calling code. Callers can skip them or name them, as in Print(text, count: 3).

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.