How to: Pass Object Arrays to Methods
This example shows how an array of objects is passed to the DisplayMyCollection method, which uses the params keyword to accept any number of arguments.
Example
class MyBoxingClass
{
public static void DisplayMyCollection(params object[] anArray)
{
foreach (object obj in anArray)
{
System.Console.Write(obj + "\t");
}
// Suspend the screen.
System.Console.ReadLine();
}
static void Main()
{
DisplayMyCollection(101, "Visual C# Basics", 2002);
}
}
Compiling the Code
You can compile the example directly using the command line, or paste it into a console application.