The params keyword lets you specify a method parameter that takes an argument where the number of arguments is variable.
For example,
{
TestArgsMethod("Hello", " goodbye ", " hello");
TestArgsMethod("Numbers", 1, 2, 3, 4);
}
static void TestArgsMethod(String text, params Object[] args)
{
StringBuilder sb = new StringBuilder();
sb.Append(text);
foreach(Object o in args)
{
sb.Append(o.ToString());
}
Debug.WriteLine(sb.ToString());
}
No comments:
Post a Comment