📄 14.5.4.htm
字号:
<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.5.3.htm"><img src="previous.gif" alt="previous" border="0" /></a><a href="14.5.4.1.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.4.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="14.6.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="14.5.htm">14.5</a></span><span class="clause-title-previous"> Primary expressions</span></span><span class="clause-depth"><a href="14.5.3.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="14.5.5.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number">14.5.4</span><span class="clause-title"> Member access</span></span><span class="locator">
Paragraph 1</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P1S1"></a>A <span class="non-terminal"><a href="14.5.4.htm#member-access">member-access</a></span> consists of a <span class="non-terminal"><a href="14.5.htm#primary-expression">primary-expression</a></span> or a <span class="non-terminal"><a href="14.5.4.htm#predefined-type">predefined-type</a></span>, followed by a "." token, followed by an identifier.</span> <span class="grammar-production"><span class="name"><a name="member-access"></a>member-access</span> : <span class="rhs"><span class="non-terminal"><a href="14.5.htm#primary-expression">primary-expression</a></span> <span class="terminal">.</span> <span class="non-terminal"><a href="9.4.2.htm#identifier">identifier</a></span> </span><span class="rhs"><span class="non-terminal"><a href="14.5.4.htm#predefined-type">predefined-type</a></span> <span class="terminal">.</span> <span class="non-terminal"><a href="9.4.2.htm#identifier">identifier</a></span> </span></span><span class="grammar-production"><span class="name"><a name="predefined-type"></a>predefined-type</span> : one of <span class="rhs"><span class="keyword">bool</span> <span class="keyword">byte</span> <span class="keyword">char</span> <span class="keyword">decimal</span> <span class="keyword">double</span> <span class="keyword">float</span> <span class="keyword">int</span> <span class="keyword">long</span> </span><span class="rhs"><span class="keyword">object</span> <span class="keyword">sbyte</span> <span class="keyword">short</span> <span class="keyword">string</span> <span class="keyword">uint</span> <span class="keyword">ulong</span> <span class="keyword">ushort</span> </span></span></span><span class="locator">
Paragraph 2</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P2S1"></a>A <span class="non-terminal"><a href="14.5.4.htm#member-access">member-access</a></span> of the form E.I, where E is a <span class="non-terminal"><a href="14.5.htm#primary-expression">primary-expression</a></span> or a <span class="non-terminal"><a href="14.5.4.htm#predefined-type">predefined-type</a></span> and I is an identifier, is evaluated and classified as follows: </span><ul><li><span class="sentence"><span class="sentence-number">2</span> <a name="P2S2"></a> If E is a namespace and I is the name of an accessible member of that namespace, then the result is that member and, depending on the member, is classified as a namespace or a type.</span> </li><li><span class="sentence"><span class="sentence-number">3</span> <a name="P2S3"></a> If E is a <span class="non-terminal"><a href="14.5.4.htm#predefined-type">predefined-type</a></span> or a <span class="non-terminal"><a href="14.5.htm#primary-expression">primary-expression</a></span> classified as a type, and a member lookup (<a href="14.3.htm">§14.3</a>) of I in E produces a match, then E.I is evaluated and classified as follows: </span></li><ul><li><span class="sentence"><span class="sentence-number">4</span> <a name="P2S4"></a> If I identifies a type, then the result is that type.</span> </li><li><span class="sentence"><span class="sentence-number">5</span> <a name="P2S5"></a> If I identifies one or more methods, then the result is a method group with no associated instance expression.</span> </li><li><span class="sentence"><span class="sentence-number">6</span> <a name="P2S6"></a> If I identifies a static property, then the result is a property access with no associated instance expression.</span> </li><li><span class="sentence"><span class="sentence-number">7</span> <a name="P2S7"></a> If I identifies a static field: </span></li><ul><li><span class="sentence"><span class="sentence-number">8</span> <a name="P2S8"></a> If the field is readonly and the reference occurs outside the static constructor of the class or struct in which the field is declared, then the result is a value, namely the value of the static field I in E.</span> </li><li><span class="sentence"><span class="sentence-number">9</span> <a name="P2S9"></a> Otherwise, the result is a variable, namely the static field I in E.</span> </li></ul><li><span class="sentence"><span class="sentence-number">10</span> <a name="P2S10"></a> If I identifies a static event: </span></li><ul><li><span class="sentence"><span class="sentence-number">11</span> <a name="P2S11"></a> If the reference occurs within the class or struct in which the event is declared, and the event was declared without <span class="non-terminal"><a href="17.7.htm#event-accessor-declarations">event-accessor-declarations</a></span> (<a href="17.7.htm">§17.7</a>), then E.I is processed exactly as if I was a static field.</span> </li><li><span class="sentence"><span class="sentence-number">12</span> <a name="P2S12"></a> Otherwise, the result is an event access with no associated instance expression.</span> </li></ul><li><span class="sentence"><span class="sentence-number">13</span> <a name="P2S13"></a> If I identifies a constant, then the result is a value, namely the value of that constant.</span> </li><li><span class="sentence"><span class="sentence-number">14</span> <a name="P2S14"></a> If I identifies an enumeration member, then the result is a value, namely the value of that enumeration member.</span> </li><li><span class="sentence"><span class="sentence-number">15</span> <a name="P2S15"></a> Otherwise, E.I is an invalid member reference, and a compile-time error occurs.</span> </li></ul><li><span class="sentence"><span class="sentence-number">16</span> <a name="P2S16"></a> If E is a property access, indexer access, variable, or value, the type of which is T, and a member lookup (<a href="14.3.htm">§14.3</a>) of I in T produces a match, then E.I is evaluated and classified as follows: </span></li><ul><li><span class="sentence"><span class="sentence-number">17</span> <a name="P2S17"></a> First, if E is a property or indexer access, then the value of the property or indexer access is obtained (<a href="14.1.1.htm">§14.1.1</a>) and E is reclassified as a value.</span> </li><li><span class="sentence"><span class="sentence-number">18</span> <a name="P2S18"></a> If I identifies one or more methods, then the result is a method group with an associated instance expression of E.</span> </li><li><span class="sentence"><span class="sentence-number">19</span> <a name="P2S19"></a> If I identifies an instance property, then the result is a property access with an associated instance expression of E.</span> </li><li><span class="sentence"><span class="sentence-number">20</span> <a name="P2S20"></a> If T is a <span class="non-terminal"><a href="11.2.htm#class-type">class-type</a></span> and I identifies an instance field of that class-type: </span></li><ul><li><span class="sentence"><span class="sentence-number">21</span> <a name="P2S21"></a> If the value of E is null, then a System.NullReferenceException is thrown.</span> </li><li><span class="sentence"><span class="sentence-number">22</span> <a name="P2S22"></a> Otherwise, if the field is readonly and the reference occurs outside an instance constructor of the class in which the field is declared, then the result is a value, namely the value of the field I in the object referenced by E.</span> </li><li><span class="sentence"><span class="sentence-number">23</span> <a name="P2S23"></a> Otherwise, the result is a variable, namely the field I in the object referenced by E.</span> </li></ul><li><span class="sentence"><span class="sentence-number">24</span> <a name="P2S24"></a> If T is a <span class="non-terminal"><a href="11.1.htm#struct-type">struct-type</a></span> and I identifies an instance field of that struct-type: </span></li><ul><li><span class="sentence"><span class="sentence-number">25</span> <a name="P2S25"></a> If E is a value, or if the field is readonly and the reference occurs outside an instance constructor of the struct in which the field is declared, then the result is a value, namely the value of the field I in the struct instance given by E.</span> </li><li><span class="sentence"><span class="sentence-number">26</span> <a name="P2S26"></a> Otherwise, the result is a variable, namely the field I in the struct instance given by E.</span> </li></ul><li><span class="sentence"><span class="sentence-number">27</span> <a name="P2S27"></a> If I identifies an instance event: </span></li><ul><li><span class="sentence"><span class="sentence-number">28</span> <a name="P2S28"></a> If the reference occurs within the class or struct in which the event is declared, and the event was declared without <span class="non-terminal"><a href="17.7.htm#event-accessor-declarations">event-accessor-declarations</a></span> (<a href="17.7.htm">§17.7</a>), then E.I is processed exactly as if I was an instance field.</span> </li><li><span class="sentence"><span class="sentence-number">29</span> <a name="P2S29"></a> Otherwise, the result is an event access with an associated instance expression of E.</span> </li></ul></ul><li><span class="sentence"><span class="sentence-number">30</span> <a name="P2S30"></a> Otherwise, E.I is an invalid member reference, and a compile-time error occurs.</span> </li></ul></span><span class="ruler"></span><table><tr><td><table align="left" bgcolor="navy"><tr bgcolor="navy"><td><font face="Arial,sans-serif" size="6" color="yellow"><strong>{ JSL }</strong></font></td></tr></table></td></tr><tr><td><font face="Arial,sans-serif" size="2" color="navy"><strong>Jagger Software Ltd</strong></font></td></tr><tr><td><font face="Arial,sans-serif" size="2" color="navy"><strong>Company # 4070126</strong></font></td></tr><tr><td><font face="Arial,sans-serif" size="2" color="navy"><strong>VAT # 762 5213 42</strong></font></td></tr></table><img src="valid-html401.png" align="left" height="31" width="88" alt="Valid HTML 4.01" /><img src="vcss.gif" align="left" height="31" width="88" alt="Valid CSS" /></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -