While researching this I found this question: Why C# allows that only the last parameter of a method is of "variable length"
While I 100% agree with the answers there and understand the rules of allowing such thing would be horrifyingly complicated as stated there, it hasn't provided me with an answer to my actual question. The linked question talks about T f(params A[] a, params B[] b), so multiple arguments with the params keyword.
But there is no mention whatsoever of the following idea:
void Foo(int head, params int[] body, int tail)
Or to be specific: Instead of asking why you can't have multiple params arguments, why can't we have a single params argument, but just not at the end (either somewhere in the middle, or at the beginning)?
I cannot think of a single reason why that would be complicated, but please prove me wrong!
For example lets suppose the following function:
void Foo(int head, params int[] body, int tail)
{
Console.WriteLine($"{head} [{string.Join(", ", body)}] {tail}");
}
I think there is no doubt about what the result should be.
Foo(1, 2) // 1 [] 2
Foo(1, 2, 3) // 1 [2] 3
Foo(1, 2, 3, 4) // 1 [2, 3] 4
There's no "How to determine where a ends and b begins then?" (top comment on the linked question) in this case so I don't see the problem.