Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Code: Passing Object Arrays to Methods (Visual C#)

Visual Studio .NET 2003

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.


class MyBoxingClass
   public static void DisplayMyCollection(params object[] anArray)
      foreach (object obj in anArray)
         System.Console.Write(obj + "\t");

      // Suspend the screen.

   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 using the Visual Studio IDE.

See Also

params Keyword | General Language Example Topics

© 2015 Microsoft