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.
Answer checked How we write and check questions
Discussion