ECMA-334 C# Language Specification17.5.1: Method parameters |
The parameters of a method, if any, are declared by the method's formal-parameter-list
.
fixed-parameters
fixed-parameters
,
parameter-array
parameter-array
fixed-parameter
fixed-parameters
,
fixed-parameter
attributes
opt parameter-modifier
opt type
identifier
attributes
optparams array-type
identifier
The formal parameter list consists of one or more comma-separated parameters of which only the last may be a parameter-array
.
A fixed-parameter
consists of an optional set of attributes (24), an optional ref or out modifier, a type, and an identifier. Each fixed-parameter
declares a parameter of the given type with the given name.
A parameter-array
consists of an optional set of attributes (24), a params modifier, an array-type
, and an identifier. A parameter array declares a single parameter of the given array type with the given name. The array-type
of a parameter array must be a single-dimensional array type (19.1). In a method invocation, a parameter array permits either a single argument of the given array type to be specified, or it permits zero or more arguments of the array element type to be specified. Parameter arrays are described further in 17.5.1.4.
A method declaration creates a separate declaration space for parameters and local variables. Names are introduced into this declaration space by the formal parameter list of the method and by local variable declarations in the block of the method. All names in the declaration space of a method must be unique. Thus, it is a compile-time error for a parameter or local variable to have the same name as another parameter or local variable.
A method invocation (14.5.5.1) creates a copy, specific to that invocation, of the formal parameters and local variables of the method, and the argument list of the invocation assigns values or variable references to the newly created formal parameters. Within the block of a method, formal parameters can be referenced by their identifiers in simple-name
expressions (14.5.2).
There are four kinds of formal parameters:
In This Section: