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

📄 10.7.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="10.6.htm"><img src="previous.gif" alt="previous" border="0" /></a><a href="10.7.1.htm"><img src="next.gif" alt="next" border="0" /></a></span><span class="clause-depth"><a href="9.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="11.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="10.htm">10</a></span><span class="clause-title-previous"> Basic concepts</span></span><span class="clause-depth"><a href="10.6.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="10.8.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number">10.7</span><span class="clause-title"> Scopes</span></span><span class="locator">
     Paragraph 1</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P1S1"></a>The scope of a name is the region of program text within which it is possible to refer to the entity declared by the name without qualification of the name.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P1S2"></a>Scopes can be nested, and an inner scope may redeclare the meaning of a name from an outer scope.</span> <span class="note">[Note: This does not, however, remove the restriction imposed by <a href="10.3.htm">&#167;10.3</a> that within a nested block it is not possible to declare a local variable with the same name as a local variable in an enclosing block. end note]</span> <span class="sentence"><span class="sentence-number">3</span> <a name="P1S3"></a>The name from the outer scope is then said to be hidden in the region of program text covered by the inner scope, and access to the outer name is only possible by qualifying the name.</span> <ul><li><span class="sentence"><span class="sentence-number">4</span> <a name="P1S4"></a> The scope of a namespace member declared by a <span class="non-terminal"><a href="16.4.htm#namespace-member-declaration">namespace-member-declaration</a></span> (<a href="16.4.htm">&#167;16.4</a>) with no enclosing <span class="non-terminal"><a href="16.2.htm#namespace-declaration">namespace-declaration</a></span> is the entire program text.</span> </li><li><span class="sentence"><span class="sentence-number">5</span> <a name="P1S5"></a> The scope of a namespace member declared by a <span class="non-terminal"><a href="16.4.htm#namespace-member-declaration">namespace-member-declaration</a></span> within a  <span class="non-terminal"><a href="16.2.htm#namespace-declaration">namespace-declaration</a></span> whose fully qualified name is N, is the <span class="non-terminal"><a href="16.2.htm#namespace-body">namespace-body</a></span> of every <span class="non-terminal"><a href="16.2.htm#namespace-declaration">namespace-declaration</a></span> whose fully qualified name is N or starts with N, followed by a period.</span> </li><li><span class="sentence"><span class="sentence-number">6</span> <a name="P1S6"></a> The scope of a name defined or imported by a <span class="non-terminal"><a href="16.3.htm#using-directive">using-directive</a></span> (<a href="16.3.htm">&#167;16.3</a>) extends over the  <span class="non-terminal"><a href="16.4.htm#namespace-member-declaration">namespace-member-declaration</a></span>s of the <span class="non-terminal"><a href="16.1.htm#compilation-unit">compilation-unit</a></span> or <span class="non-terminal"><a href="16.2.htm#namespace-body">namespace-body</a></span> in which the <span class="non-terminal"><a href="16.3.htm#using-directive">using-directive</a></span> occurs.</span> <span class="sentence"><span class="sentence-number">7</span> <a name="P1S7"></a>A <span class="non-terminal"><a href="16.3.htm#using-directive">using-directive</a></span> may make zero or more namespace or type names available within a particular  <span class="non-terminal"><a href="16.1.htm#compilation-unit">compilation-unit</a></span> or <span class="non-terminal"><a href="16.2.htm#namespace-body">namespace-body</a></span>, but does not contribute any new members to the underlying declaration space.</span> <span class="sentence"><span class="sentence-number">8</span> <a name="P1S8"></a>In other words, a <span class="non-terminal"><a href="16.3.htm#using-directive">using-directive</a></span> is not transitive, but, rather, affects only the <span class="non-terminal"><a href="16.1.htm#compilation-unit">compilation-unit</a></span> or  <span class="non-terminal"><a href="16.2.htm#namespace-body">namespace-body</a></span> in which it occurs.</span> </li><li><span class="sentence"><span class="sentence-number">9</span> <a name="P1S9"></a> The scope of a member declared by a <span class="non-terminal"><a href="17.2.htm#class-member-declaration">class-member-declaration</a></span> (<a href="17.2.htm">&#167;17.2</a>) is the <span class="non-terminal"><a href="17.1.3.htm#class-body">class-body</a></span> in which the declaration occurs.</span> <span class="sentence"><span class="sentence-number">10</span> <a name="P1S10"></a>In addition, the scope of a class member extends to the <span class="non-terminal"><a href="17.1.3.htm#class-body">class-body</a></span> of those derived classes that are included in the accessibility domain (<a href="10.5.2.htm">&#167;10.5.2</a>) of the member.</span> </li><li><span class="sentence"><span class="sentence-number">11</span> <a name="P1S11"></a> The scope of a member declared by a <span class="non-terminal"><a href="18.2.htm#struct-member-declaration">struct-member-declaration</a></span> (<a href="18.2.htm">&#167;18.2</a>) is the <span class="non-terminal"><a href="18.1.3.htm#struct-body">struct-body</a></span> in which the declaration occurs.</span> </li><li><span class="sentence"><span class="sentence-number">12</span> <a name="P1S12"></a> The scope of a member declared by an <span class="non-terminal"><a href="21.3.htm#enum-member-declaration">enum-member-declaration</a></span> (<a href="21.3.htm">&#167;21.3</a>) is the <span class="non-terminal"><a href="21.1.htm#enum-body">enum-body</a></span> in which the declaration occurs.</span> </li><li><span class="sentence"><span class="sentence-number">13</span> <a name="P1S13"></a> The scope of a parameter declared in a <span class="non-terminal"><a href="17.5.htm#method-declaration">method-declaration</a></span> (<a href="17.5.htm">&#167;17.5</a>) is the <span class="non-terminal"><a href="17.5.htm#method-body">method-body</a></span> of that  <span class="non-terminal"><a href="17.5.htm#method-declaration">method-declaration</a></span>.</span> </li><li><span class="sentence"><span class="sentence-number">14</span> <a name="P1S14"></a> The scope of a parameter declared in an <span class="non-terminal"><a href="17.8.htm#indexer-declaration">indexer-declaration</a></span> (<a href="17.8.htm">&#167;17.8</a>) is the <span class="non-terminal"><a href="17.6.2.htm#accessor-declarations">accessor-declarations</a></span> of that <span class="non-terminal"><a href="17.8.htm#indexer-declaration">indexer-declaration</a></span>.</span> </li><li><span class="sentence"><span class="sentence-number">15</span> <a name="P1S15"></a> The scope of a parameter declared in an <span class="non-terminal"><a href="17.9.htm#operator-declaration">operator-declaration</a></span> (<a href="17.9.htm">&#167;17.9</a>) is the block of that  <span class="non-terminal"><a href="17.9.htm#operator-declaration">operator-declaration</a></span>.</span> </li><li><span class="sentence"><span class="sentence-number">16</span> <a name="P1S16"></a> The scope of a parameter declared in a <span class="non-terminal"><a href="17.10.htm#constructor-declaration">constructor-declaration</a></span> (<a href="17.10.htm">&#167;17.10</a>) is the <span class="non-terminal"><a href="17.10.htm#constructor-initializer">constructor-initializer</a></span> and block of that <span class="non-terminal"><a href="17.10.htm#constructor-declaration">constructor-declaration</a></span>.</span> </li><li><span class="sentence"><span class="sentence-number">17</span> <a name="P1S17"></a> The scope of a label declared in a <span class="non-terminal"><a href="15.4.htm#labeled-statement">labeled-statement</a></span> (<a href="15.4.htm">&#167;15.4</a>) is the block in which the declaration occurs.</span> </li><li><span class="sentence"><span class="sentence-number">18</span> <a name="P1S18"></a> The scope of a local variable declared in a <span class="non-terminal"><a href="15.5.1.htm#local-variable-declaration">local-variable-declaration</a></span> (<a href="15.5.1.htm">&#167;15.5.1</a>) is the block in which the declaration occurs.</span> </li><li><span class="sentence"><span class="sentence-number">19</span> <a name="P1S19"></a> The scope of a local variable declared in a <span class="non-terminal"><a href="15.7.2.htm#switch-block">switch-block</a></span> of a switch statement (<a href="15.7.2.htm">&#167;15.7.2</a>) is the  <span class="non-terminal"><a href="15.7.2.htm#switch-block">switch-block</a></span>.</span> </li><li><span class="sentence"><span class="sentence-number">20</span> <a name="P1S20"></a> The scope of a local variable declared in a <span class="non-terminal"><a href="15.8.3.htm#for-initializer">for-initializer</a></span> of a for statement (<a href="15.8.3.htm">&#167;15.8.3</a>) is the  <span class="non-terminal"><a href="15.8.3.htm#for-initializer">for-initializer</a></span>, the <span class="non-terminal"><a href="15.8.3.htm#for-condition">for-condition</a></span>, the <span class="non-terminal"><a href="15.8.3.htm#for-iterator">for-iterator</a></span>, and the contained statement of the for statement.</span> </li><li><span class="sentence"><span class="sentence-number">21</span> <a name="P1S21"></a> The scope of a local constant declared in a <span class="non-terminal"><a href="15.5.2.htm#local-constant-declaration">local-constant-declaration</a></span> (<a href="15.5.2.htm">&#167;15.5.2</a>) is the block in which the declaration occurs.</span> <span class="sentence"><span class="sentence-number">22</span> <a name="P1S22"></a>It is a compile-time error to refer to a local constant in a textual position that precedes its <span class="non-terminal"><a href="17.3.htm#constant-declarator">constant-declarator</a></span>.</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>Within the scope of a namespace, class, struct, or enumeration member it is possible to refer to the member in a textual position that precedes the declaration of the member.</span> <span class="example">[Example: For example <pre class="code-example">
class A  
{  
   void F() {  
      i = 1;  
   }  
   int i = 0;  
}  
</pre></span></span><span class="paragraph"><span class="example">Here, it is valid for F to refer to i before it is declared. end example]</span> </span><span class="locator">
     Paragraph 3</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P3S1"></a>Within the scope of a local variable, it is a compile-time error to refer to the local variable in a textual position that precedes the <span class="non-terminal"><a href="15.5.1.htm#local-variable-declarator">local-variable-declarator</a></span> of the local variable.</span> <span class="example">[Example: For example <pre class="code-example">
class A  
{  
   int i = 0;  
   void F() {  
      i = 1;      // Error, use precedes declaration  
      int i;  
      i = 2;  
   }  
   void G() {  

⌨️ 快捷键说明

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