C#中的命名参数和params关键字 [英] Named Parameters and the params keyword in C#
本文介绍了C#中的命名参数和params关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C#方法,该方法具有使用 params
关键字声明的变长参数列表:
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?
推荐答案
您可以使用命名参数来调用它,如下所示:
You can call it using named parameter like this:
VariableLengthParameterFunction(
secondParam: new object[] { 5, 7, 3, 2 },
firstParam: 4);
这篇关于C#中的命名参数和params关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文