Come posso avere un parametro di params
con almeno un valore?
public void Foo(params string[] s) { } public void main() { this.Foo(); // compile error this.Foo(new string[0]); // compile error this.Foo({ }); // compile error this.Foo("foo"); // no error this.Foo("foo1", "foo2"); // no error }
Basta fare:
public void Foo(string first, params string[] s) { }
Non è ansible specificare tali condizioni per i params
in fase di compilazione.
Tuttavia, è ansible verificarlo a run-time e generare un’eccezione se le condizioni specificate non vengono soddisfatte.