Indicates that a method will allow a variable number of arguments in its invocation. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|Equals||Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)|
|GetHashCode||Returns the hash code for this instance. (Inherited from Attribute.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|IsDefaultAttribute||When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)|
|Match||When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|_Attribute::GetIDsOfNames||Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)|
|_Attribute::GetTypeInfo||Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)|
|_Attribute::GetTypeInfoCount||Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)|
|_Attribute::Invoke||Provides access to properties and methods exposed by an object. (Inherited from Attribute.)|
The 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 in the next section illustrates both calling conventions.
Typically, the 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 class. Some languages, such as C#, may even require the use of the language keyword and prohibit the use of .
During overload resolution, when compilers that support parameter arrays encounter a method overload that does not exist but has one fewer parameter than an overload that includes a parameter array, they will replace the method with the overload that includes the parameter array. For example, a call to the String.Split() instance method (which does not exist in the String class) is resolved as a call to the String::Split(array<Char>) method. The compiler will also pass an empty array of the required type to the method. This means that the method must always be prepared to handle an array whose length is zero when it processes the elements in the parameter array. 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.
The following example illustrates three different calls to the Temperature.Display method. In the first, the method is passed an array of format strings. In the second, the method is passed four individual format strings as arguments. In the third, 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.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8