海鸥航迹

学习之笔记,好文之收集。

导航

[导入]Does C# support variable arguments (vararg's) on methods?

There was a suggestion/question on the Product Feedback site for VS2005 that suggested that the params keyword may not be that well understood.

The params keyword can be applied on a method parameter that is an array.  When the method is invoked, the elements of the array can be supplied as a comma separated list.

So, if the method parameter is an object array,

void paramsExample(object arg1, object arg2, params object[] argsRest)

{

foreach (object arg in argsRest)

{ /* .... */ }

}

 

then the method can be invoked with any number of arguments of any type.

paramsExample(1, 0.0f, "a string", 0.0m, new UserDefinedType());

 

[SantoshZ]


文章来源:http://blogs.msdn.com/csharpfaq/archive/2004/08/05/209384.aspx

posted on 2004-09-22 09:33  海天一鸥  阅读(788)  评论(1编辑  收藏  举报