Practice mode C#

Given static int Sum(params int n) => n.Length;, what does Sum() return?

Correct answer B. 0

Explanation

A params parameter lets callers pass zero or more arguments, which the compiler packs into an array. When no arguments are supplied, the method receives an empty array, not null, so n.Length is 0. A params parameter must be the last one in the list, and only one is allowed per method. Calls such as Sum(1, 2, 3) return 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.