X hits on this document

1001 views

0 shares

0 downloads

0 comments

231 / 396

C# LANGUAGE SPECIFICATION

A fixed-parameter consists of an optional set of attributes (§‎17), 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 (§‎17), 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 (§‎12.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 §‎10.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; otherwise, a compile-time error results.

A method invocation (§‎7.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 (§‎7.5.2).

There are four kinds of formal parameters:

Value parameters, which are declared without any modifiers.

Reference parameters, which are declared with the ref modifier.

Output parameters, which are declared with the out modifier.

Parameter arrays, which are declared with the params modifier.

As described in §‎3.6, the ref and out modifiers are part of a method’s signature, but the params modifier is not.

10.5.1.1 Value parameters

A parameter declared with no modifiers is a value parameter. A value parameter corresponds to a local variable that gets its initial value from the corresponding argument supplied in the method invocation.

When a formal parameter is a value parameter, the corresponding argument in a method invocation must be an expression of a type that is implicitly convertible (§‎6.1) to the formal parameter type.

A method is permitted to assign new values to a value parameter. Such assignments only affect the local storage location represented by the value parameter—they have no effect on the actual argument given in the method invocation.

10.5.1.2 Reference parameters

A parameter declared with a ref modifier is a reference parameter. Unlike a value parameter, a reference parameter does not create a new storage location. Instead, a reference parameter represents the same storage location as the variable given as the argument in the method invocation.

When a formal parameter is a reference parameter, the corresponding argument in a method invocation must consist of the keyword ref followed by a variable-reference (§‎5.3.3) of the same type as the formal parameter. A variable must be definitely assigned before it can be passed as a reference parameter.

Within a method, a reference parameter is always considered definitely assigned.

The example

using System;

218Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1001
Page views1001
Page last viewedFri Dec 09 12:17:51 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments