Reputation: 198
An overloaded method sample, for named parameter call:
internal static dynamic TestMethod(int P1a, int P1b, params dynamic[] P1c)
{
//Sample Code
}
[Overload: P2] //illustration : Overload Specification
internal static dynamic TestMethod(int P2a, int P2b, params dynamic[] P2c)
{
//Sample Code
}
Having a new set of code organization, is to specify which overload to use using named parameters would resolve the problem or declare the method for overload selection;
TestMethod(P2: 1, 1,2,3,4,5);
Upvotes: 0
Views: 307
Reputation: 239764
They two features are not compatible. You would have to construct the array yourself, rather than having the compiler do that for you (an array is always constructed either way).
How do we know they're not compatible? From Argument lists:
An argument with an argument_name is referred to as a named argument, whereas an argument without an argument_name is a positional argument. It is an error for a positional argument to appear after a named argument in an argument_list.
Note that last sentence - you cannot have positional arguments after a named argument.
Runtime evaluation of argument lists:
Methods, indexers, and instance constructors may declare their right-most parameter to be a parameter array
...
When a function member with a parameter array is invoked in its expanded form, the invocation must specify zero or more positional arguments for the parameter array ...
(My emphasis)
That is, the params
feature only works with positional arguments.
Upvotes: 4