Practice mode C#

What rule applies to an out parameter in C#?

Correct answer B. The method must assign it before returning; the caller need not initialise it

Explanation

out passes an argument by reference for output. The called method must definitely assign every out parameter before it returns normally, while the caller may pass an unassigned variable. This is how int.TryParse("42", out int n) returns both a bool and the parsed value. The read-only by-reference modifier is in, and ref requires initialisation by the caller.

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.