Passing zero arguments as params -- where the behaviour is defined?

greenoldman picture greenoldman · May 31, 2010 · Viewed 8.1k times · Source

C# spec. allows you to call a function

void foo(params int[] x)

with zero parameters. However, I didn't find in C# Lang. Spec. a word on further behaviour -- will foo get empty array or null reference? I checked also MSDN -- nothing.

Where the behaviour is defined?

NOTE: I am not asking how VS behaves, I am asking about design of the language.

Answer

Anthony Pegram picture Anthony Pegram · May 31, 2010

Section 7.4.1 of the C# Language Specification (ref: C# 3.0 spec)

In particular, note that an empty array is created when there are zero arguments given for the parameter array.

It's the last line of the section