Is there a C# alternative to Java's vararg parameters? -
i have worked on java , new .net technology
is possible declare function in c# accepts variable input parameters
is there c# syntax similar following java syntax?
void f1(string... a)
yes, c# has equivalent of varargs parameters. they're called parameter arrays, , introduced params modifier:
public void foo(int x, params string[] values) then call with:
foo(10, "hello", "there"); just java, it's last parameter can vary this. note (as java) parameter of params object[] objects can cause confusion, need remember whether single argument of type object[] meant wrapped again or not. likewise nullable type, need remember whether single argument of null treated array reference or single array element. (i think compiler creates array if has to, tend write code avoids me having remember that.)
Comments
Post a Comment