marosoaie marosoaie - 10 days ago 5
C# Question

Named Parameters and the params keyword in C#

I have a C# method with a variable length argument list declared using the

params
keyword:

public void VariableLengthParameterFunction (object firstParam,
params object[] secondParam)


Is there any way of using named parameters when calling the method?

Answer

You can call it using named parameter like this:

VariableLengthParameterFunction(
    secondParam: new object[] { 5, 7, 3, 2 }, 
    firstParam: 4);
Comments