Search

Call with variable arguments

This C# code snippet uses the params keyword to implement a method which can be called with a variable number of arguments.
using System;
 
static void ListArguments (params object[] arguments)
{
   foreach (object argument in arguments)
   {
      Console.WriteLine (argument);
   }
}
 
public static void Main( )
{
   ListArguments ("Arguments: ", DateTime.Now, 3.14f);
}