Call with variable arguments

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet uses the params keyword to implement a method which can be called with a variable number of arguments.

static void ListArguments (params object[] arguments)
{
   foreach (object argument in arguments)
   {
      Console.WriteLine (argument);
   }
}
 
public static void Main( )
{
   ListArguments ("Arguments: ", DateTime.Now, 3.14f);
}


Personal tools