Why does passing null to a params method result in a null parameter array?

A params parameter is only meant to provide a convenient way of specifying values – you can still pass an array reference directly.

Now, null is convertible to either string[] or string, so both interpretations are valid – it’s up to the spec which is preferred. The spec states in section 10.6.1.4 that:

  • The argument given for a parameter array can be a single expression that is implicitly convertible to the parameter array type. In this case, the parameter array acts precisely like a value parameter.

  • Alternatively, […]

In other words, the compiler checks to see whether the argument is valid as the “normal” parameter type first, and only builds an array if it absolutely has to.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)