Saturday, September 14, 2013

Named arguments call in C# with variable parameter number

Named arguments call in C# with variable parameter number

Suppose I have the following C# function:
void Foo(int bar, params string[] parpar) { }
I want to call this function using named arguments:
Foo(bar: 5, parpar: "a", "b", "c");
The compiler gives error message: "Named arguments cannot precede
positional" since I have no name before "b" and "c".
Is there any way to use named arguments without manually representing
params as an array?

No comments:

Post a Comment