you could just do,
Thing(1, string.Empty, new Hello(), new Hello());
since you are using params
.
For that matter all these would be compatible.
Thing(1);
Thing(2, string.Empty);
Thing(3, string.Empty, null);
Thing(4, string.Empty, new Hello());
Thing(-69, "negative feeback", new Hello(), null);
Thing(42, "the meaning of life", new Hello(), new Hello());
Thing(666, theBeast.ToString(), new Hello(), new Hello(), new Hello());
// etc. etc.
From your comment I think your question is actually,
Why do I have to construct the params
array when using parameter names?
That question is a duplicate but, in summary its because, thats the way it works.
If you want to omit s
and get the benefits of params
why not declare the overload,
public void Thing(int x, string s = "", params Hello[] hellos)
{
}
public void Thing(int x, params Hello[] hellos)
{
this.Thing(x, string.Empty, hellos);
}
Then you can still use params
as intended and you don't need to use parameter names.
This functionality is older than optional parameters and largely mitigates your requirement, which I guess is why its never been addressed.