⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14.4.1.htm

📁 This ECMA Standard specifies the form and establishes the interpretation of programs written in the
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Hyperlinked ECMA C# Language Specification</title><meta name="author" content="Jon Jagger" /><link rel="stylesheet" href="ecma334.css"></link></head><body><div align="right"><em><a href="http://www.jaggersoft.com">Jon Jagger</a></em></div><div align="right"><a href="mailto:jon@jaggersoft.com">jon@jaggersoft.com</a></div><form method="get" action="http://search.atomz.com/search/"><input size="30" name="sp-q"></input><input type="submit" value="Search C# Spec"></input><input type="hidden" name="sp-a" value="sp10024177"></input><input type="hidden" name="sp-f" value="ISO-8859-1"></input></form><a href="toc.htm">Table of Contents</a> <a href="1.htm">1</a> <a href="2.htm">2</a> <a href="3.htm">3</a> <a href="4.htm">4</a> <a href="5.htm">5</a> <a href="6.htm">6</a> <a href="7.htm">7</a> <a href="8.htm">8</a> <a href="9.htm">9</a> <a href="10.htm">10</a> <a href="11.htm">11</a> <a href="12.htm">12</a> <a href="13.htm">13</a> <a href="14.htm">14</a> <a href="15.htm">15</a> <a href="16.htm">16</a> <a href="17.htm">17</a> <a href="18.htm">18</a> <a href="19.htm">19</a> <a href="20.htm">20</a> <a href="21.htm">21</a> <a href="22.htm">22</a> <a href="23.htm">23</a> <a href="24.htm">24</a> <a href="25.htm">25</a> <a href="notes.htm">Notes</a> <a href="HyperlinkedCSharpECMA.zip">Download</a><span class="ruler"></span><span class="heading">ECMA-334 C# Language Specification</span><span class="navigate"><a href="14.4.htm"><img src="previous.gif" alt="previous" border="0" /></a><a href="14.4.2.htm"><img src="next.gif" alt="next" border="0" /></a></span><span class="clause-depth"><a href="13.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="15.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="14.htm">14</a></span><span class="clause-title-previous"> Expressions</span></span><span class="clause-depth"><a href="14.3.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="14.5.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="14.4.htm">14.4</a></span><span class="clause-title-previous"> Function members</span></span><span class="clause-depth"><a href="14.4.1.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="14.4.2.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number">14.4.1</span><span class="clause-title"> Argument lists</span></span><span class="locator">
     Paragraph 1</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P1S1"></a>Every function member invocation includes an argument list, which provides actual values or variable references for the parameters of the function member.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P1S2"></a>The syntax for specifying the argument list of a function member invocation depends on the function member category: </span><ul><li><span class="sentence"><span class="sentence-number">3</span> <a name="P1S3"></a> For instance constructors, methods, and delegates, the arguments are specified as an <span class="non-terminal"><a href="14.4.1.htm#argument-list">argument-list</a></span>, as described below.</span> </li><li><span class="sentence"><span class="sentence-number">4</span> <a name="P1S4"></a> For properties, the argument list is empty when invoking the get accessor, and consists of the expression specified as the right operand of the assignment operator when invoking the set accessor.</span> </li><li><span class="sentence"><span class="sentence-number">5</span> <a name="P1S5"></a> For events, the argument list consists of the expression specified as the right operand of the += or -= operator.</span> </li><li><span class="sentence"><span class="sentence-number">6</span> <a name="P1S6"></a> For indexers, the argument list consists of the expressions specified between the square brackets in the indexer access.</span> <span class="sentence"><span class="sentence-number">7</span> <a name="P1S7"></a>When invoking the set accessor, the argument list additionally includes the expression specified as the right operand of the assignment operator.</span> </li><li><span class="sentence"><span class="sentence-number">8</span> <a name="P1S8"></a> For user-defined operators, the argument list consists of the single operand of the unary operator or the two operands of the binary operator.</span> </li></ul></span><span class="locator">
     Paragraph 2</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P2S1"></a>The arguments of properties (<a href="17.6.htm">&#167;17.6</a>), events (<a href="17.7.htm">&#167;17.7</a>), indexers (<a href="17.8.htm">&#167;17.8</a>), and user-defined operators (<a href="17.9.htm">&#167;17.9</a>) are always passed as value parameters (<a href="17.5.1.1.htm">&#167;17.5.1.1</a>).</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P2S2"></a>Reference and output parameters are not supported for these categories of function members.</span> </span><span class="locator">
     Paragraph 3</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P3S1"></a>The arguments of an instance constructor, method, or delegate invocation are specified as an argument-list: <span class="grammar-production"><span class="name"><a name="argument-list"></a>argument-list</span> : <span class="rhs"><span class="non-terminal"><a href="14.4.1.htm#argument">argument</a></span> </span><span class="rhs"><span class="non-terminal"><a href="14.4.1.htm#argument-list">argument-list</a></span> <span class="terminal">,</span> <span class="non-terminal"><a href="14.4.1.htm#argument">argument</a></span> </span></span><span class="grammar-production"><span class="name"><a name="argument"></a>argument</span> : <span class="rhs"><span class="non-terminal"><a href="14.14.htm#expression">expression</a></span> </span><span class="rhs"><span class="keyword">ref</span> <span class="non-terminal"><a href="12.4.htm#variable-reference">variable-reference</a></span> </span><span class="rhs"><span class="keyword">out</span> <span class="non-terminal"><a href="12.4.htm#variable-reference">variable-reference</a></span> </span></span></span></span><span class="locator">
     Paragraph 4</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P4S1"></a>An <span class="non-terminal"><a href="14.4.1.htm#argument-list">argument-list</a></span> consists of one or more arguments, separated by commas.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P4S2"></a>Each argument can take one of the following forms: </span><ul><li><span class="sentence"><span class="sentence-number">3</span> <a name="P4S3"></a> An expression, indicating that the argument is passed as a value parameter (<a href="17.5.1.1.htm">&#167;17.5.1.1</a>).</span> </li><li><span class="sentence"><span class="sentence-number">4</span> <a name="P4S4"></a> The keyword ref followed by a <span class="non-terminal"><a href="12.4.htm#variable-reference">variable-reference</a></span> (<a href="12.3.3.htm">&#167;12.3.3</a>), indicating that the argument is passed as a reference parameter (<a href="17.5.1.2.htm">&#167;17.5.1.2</a>).</span> <span class="sentence"><span class="sentence-number">5</span> <a name="P4S5"></a>A variable must be definitely assigned (<a href="12.3.htm">&#167;12.3</a>) before it can be passed as a reference parameter.</span> <span class="sentence"><span class="sentence-number">6</span> <a name="P4S6"></a>A volatile field (<a href="17.4.3.htm">&#167;17.4.3</a>) cannot be passed as a reference parameter.</span> </li><li><span class="sentence"><span class="sentence-number">7</span> <a name="P4S7"></a> The keyword out followed by a <span class="non-terminal"><a href="12.4.htm#variable-reference">variable-reference</a></span> (<a href="12.3.3.htm">&#167;12.3.3</a>), indicating that the argument is passed as an output parameter (<a href="17.5.1.3.htm">&#167;17.5.1.3</a>).</span> <span class="sentence"><span class="sentence-number">8</span> <a name="P4S8"></a>A variable is considered definitely assigned (<a href="12.3.htm">&#167;12.3</a>) following a function member invocation in which the variable is passed as an output parameter.</span> <span class="sentence"><span class="sentence-number">9</span> <a name="P4S9"></a>A volatile field (<a href="17.4.3.htm">&#167;17.4.3</a>) cannot be passed as an output parameter.</span> </li></ul></span><span class="locator">
     Paragraph 5</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P5S1"></a>During the run-time processing of a function member invocation (<a href="14.4.3.htm">&#167;14.4.3</a>), the expressions or variable references of an argument list are evaluated in order, from left to right, as follows: </span><ul><li><span class="sentence"><span class="sentence-number">2</span> <a name="P5S2"></a> For a value parameter, the argument expression is evaluated and an implicit conversion (<a href="13.1.htm">&#167;13.1</a>) to the corresponding parameter type is performed.</span> <span class="sentence"><span class="sentence-number">3</span> <a name="P5S3"></a>The resulting value becomes the initial value of the value parameter in the function member invocation.</span> </li><li><span class="sentence"><span class="sentence-number">4</span> <a name="P5S4"></a> For a reference or output parameter, the variable reference is evaluated and the resulting storage location becomes the storage location represented by the parameter in the function member invocation.</span> <span class="sentence"><span class="sentence-number">5</span> <a name="P5S5"></a>If the variable reference given as a reference or output parameter is an array element of a <span class="non-terminal"><a href="11.2.htm#reference-type">reference-type</a></span>, a run-time check is performed to ensure that the element type of the array is identical to the type of the parameter.</span> <span class="sentence"><span class="sentence-number">6</span> <a name="P5S6"></a>If this check fails, a System.ArrayTypeMismatchException is thrown.</span> </li></ul></span><span class="locator">
     Paragraph 6</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P6S1"></a>Methods, indexers, and instance constructors may declare their right-most parameter to be a parameter array (<a href="17.5.1.4.htm">&#167;17.5.1.4</a>).</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P6S2"></a>Such function members are invoked either in their normal form or in their expanded form depending on which is applicable (<a href="14.4.2.1.htm">&#167;14.4.2.1</a>): </span><ul><li><span class="sentence"><span class="sentence-number">3</span> <a name="P6S3"></a> When a function member with a parameter array is invoked in its normal form, the argument given for the parameter array must be a single expression of a type that is implicitly convertible (<a href="13.1.htm">&#167;13.1</a>) to the parameter array type.</span> <span class="sentence"><span class="sentence-number">4</span> <a name="P6S4"></a>In this case, the parameter array acts precisely like a value parameter.</span> </li><li><span class="sentence"><span class="sentence-number">5</span> <a name="P6S5"></a> When a function member with a parameter array is invoked in its expanded form, the invocation must specify zero or more arguments for the parameter array, where each argument is an expression of a type that is implicitly convertible (<a href="13.1.htm">&#167;13.1</a>) to the element type of the parameter array.</span> <span class="sentence"><span class="sentence-number">6</span> <a name="P6S6"></a>In this case, the invocation creates an instance of the parameter array type with a length corresponding to the number of arguments, initializes the elements of the array instance with the given argument values, and uses the newly created array instance as the actual argument.</span> </li></ul></span><span class="locator">
     Paragraph 7</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P7S1"></a>The expressions of an argument list are always evaluated in the order they are written.</span> <span class="example">[Example: Thus, the example <pre class="code-example">
class Test  
{  
   static void F(int x, int y, int z) {  
      System.Console.WriteLine("x = {0}, y = {1}, z = {2}", x, y, z);  
   }  
   static void Main() {  
      int i = 0;  
      F(i++, i++, i++);  
   }  
}  
</pre>produces the output <pre class="code-example">
x = 0, y = 1, z = 2  
</pre>end example]</span> </span><span class="locator">
     Paragraph 8</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P8S1"></a>The array covariance rules (<a href="19.5.htm">&#167;19.5</a>) permit a value of an array type A[] to be a reference to an instance of an array type B[], provided an implicit reference conversion exists from B to A.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P8S2"></a>Because of these rules, when an array element of a <span class="non-terminal"><a href="11.2.htm#reference-type">reference-type</a></span> is passed as a reference or output parameter, a run-time check is required to ensure that the actual element type of the array is identical to that of the parameter.</span> <span class="example">[Example: In the example <pre class="code-example">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -