This documentation is archived and is not being maintained.

ParamArrayAttribute Class

Updated: December 2008

Indicates that the method will allow a variable number of arguments in its invocation. This class cannot be inherited.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
public sealed class ParamArrayAttribute : Attribute

The ParamArrayAttribute indicates that a method parameter is a parameter array. A parameter array allows the specification of an unknown number of arguments. A parameter array must be the last parameter in a formal parameter list, and it must be a single-dimension array. When the method is called, a parameter array permits arguments to a method to be specified in either of two ways:

  • As a single expression of a type that is implicitly convertible to the parameter array type. The parameter array functions as a value parameter.

  • As zero or more arguments where each argument is an expression of a type that is implictly convertible to the type of the parameter array element.

The example illustrates both calling conventions.


Typically, the ParamArrayAttribute is not used directly in code. Instead, individual language keywords, such as ParamArray in Visual Basic and params in C#, are used as wrappers for the ParamArrayAttribute class. Some languages, such as C#, may even require the use of the language keyword and prohibit the use of ParamArrayAttribute.

In performing overload resolution, compilers that support parameter arrays substitute a call to the method that includes a parameter array if the method that is actually called in code does not exist but has one fewer parameter than the method that includes the parameter array. For example, a call to the String.Split() instance method with no parameters (a method that does not actually exist in the String class) is resolved as a call to the String.Split(Char[]) method. The compiler also passes an empty array of the required type to the method. This means that, when the method processes the elements in the parameter array, it must always be prepared to handle an array whose length is zero. The example provides an illustration.

For more information about using attributes, see Extending Metadata Using Attributes.

The following example defines a Temperature class that includes a Display method, which is intended to display one or more formatted temperature values. The method has a single parameter, formats, which is defined as a parameter array.

using System;

public class Temperature
   private decimal temp;

   public Temperature(decimal temperature)
      this.temp = temperature;

   public override string ToString() 
      return ToString("C");

   public string ToString(string format)
      if (String.IsNullOrEmpty(format))
         format = "G";

      switch (format.ToUpper())
         case "G":
         case "C":
            return temp.ToString("N") + "  °C";
         case "F":
            return (9 * temp / 5 + 32).ToString("N") + "  °F";
         case "K": 
            return (temp + 273.15m).ToString("N") + "  °K";
            throw new FormatException(String.Format("The '{0}' format specifier is not supported", 

   public void Display(params string []formats)
      if (formats.Length == 0)
         foreach (string format in formats)
            try {
            // If there is an exception, do nothing. 
            catch { }

The following example illustrates three different calls to the Temperature.Display method. In the first call, the method is passed an array of format strings. In the second call, the method is passed four individual format strings as arguments. In the third call, the method is called with no arguments. As the output from the example illustrates, the Visual Basic and C# compilers translate this into a call to the Display method with an empty string array.

public class Class1
   public static void Main()
      Temperature temp1 = new Temperature(100);
      string[] formats = { "C", "G", "F", "K" }; 

      // Call Display method with a string array.
      Console.WriteLine("Calling Display with a string array:");

      // Call Display method with individual string arguments.
      Console.WriteLine("Calling Display with individual arguments:");
      temp1.Display("C", "F", "K", "G");

      // Call parameterless Display method.
      Console.WriteLine("Calling Display with an implicit parameter array:");
// The example displays the following output: 
//       Calling Display with a string array: 
//       100.00  °C 
//       100.00  °C 
//       212.00  °F 
//       373.15  °K 
//       Calling Display with individual arguments: 
//       100.00  °C 
//       212.00  °F 
//       373.15  °K 
//       100.00  °C 
//       Calling Display with an implicit parameter array: 
//       100.00  °C


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0




December 2008

Expanded the Remarks section and added an example.

Customer feedback.