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

📄 20.4.2.htm

📁 This ECMA Standard specifies the form and establishes the interpretation of programs written in the
💻 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="20.4.1.htm"><img src="previous.gif" alt="previous" border="0" /></a><a href="20.4.3.htm"><img src="next.gif" alt="next" border="0" /></a></span><span class="clause-depth"><a href="19.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="21.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="20.htm">20</a></span><span class="clause-title-previous"> Interfaces</span></span><span class="clause-depth"><a href="20.3.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="20.4.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number-link"><a href="20.4.htm">20.4</a></span><span class="clause-title-previous"> Interface implementations</span></span><span class="clause-depth"><a href="20.4.1.htm"><img src="previous.gif" alt="previous at this level" border="0" /></a><a href="20.4.3.htm"><img src="next.gif" alt="next at this level" border="0" /></a> <span class="clause-number">20.4.2</span><span class="clause-title"> Interface mapping</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 class or struct must provide implementations of all members of the interfaces that are listed in the base class list of the class or struct.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P1S2"></a>The process of locating implementations of interface members in an implementing class or struct is known as interface mapping.</span> </span><span class="locator">
     Paragraph 2</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P2S1"></a>Interface mapping for a class or struct C locates an implementation for each member of each interface specified in the base class list of C.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P2S2"></a>The implementation of a particular interface member I.M, where I is the interface in which the member M is declared, is determined by examining each class or struct S, starting with C and repeating for each successive base class of C, until a match is located: </span><ul><li><span class="sentence"><span class="sentence-number">3</span> <a name="P2S3"></a> If S contains a declaration of an explicit interface member implementation that matches I and M, then this member is the implementation of I.M.</span> </li><li><span class="sentence"><span class="sentence-number">4</span> <a name="P2S4"></a> Otherwise, if S contains a declaration of a non-static public member that matches M, then this member is the implementation of I.M.</span> </li></ul></span><span class="locator">
     Paragraph 3</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P3S1"></a>A compile-time error occurs if implementations cannot be located for all members of all interfaces specified in the base class list of C.</span> <span class="sentence"><span class="sentence-number">2</span> <a name="P3S2"></a>Note that the members of an interface include those members that are inherited from base interfaces.</span> </span><span class="locator">
     Paragraph 4</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P4S1"></a>For purposes of interface mapping, a class member A matches an interface member B when: </span><ul><li><span class="sentence"><span class="sentence-number">2</span> <a name="P4S2"></a> A and B are methods, and the name, type, and formal parameter lists of A and B are identical.</span> </li><li><span class="sentence"><span class="sentence-number">3</span> <a name="P4S3"></a> A and B are properties, the name and type of A and B are identical, and A has the same accessors as B (A is permitted to have additional accessors if it is not an explicit interface member implementation).</span> </li><li><span class="sentence"><span class="sentence-number">4</span> <a name="P4S4"></a> A and B are events, and the name and type of A and B are identical.</span> </li><li><span class="sentence"><span class="sentence-number">5</span> <a name="P4S5"></a> A and B are indexers, the type and formal parameter lists of A and B are identical, and A has the same accessors as B (A is permitted to have additional accessors if it is not an explicit interface member implementation).</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>Notable implications of the interface-mapping algorithm are: </span><ul><li><span class="sentence"><span class="sentence-number">2</span> <a name="P5S2"></a> Explicit interface member implementations take precedence over other members in the same class or struct when determining the class or struct member that implements an interface member.</span> </li><li><span class="sentence"><span class="sentence-number">3</span> <a name="P5S3"></a> Neither non-public nor static members participate in interface mapping.</span> </li></ul></span><span class="paragraph"><span class="example">[Example: In the example <pre class="code-example">
interface ICloneable  
{  
   object Clone();  
}  
class C: ICloneable  
{  
   object ICloneable.Clone() {...}  
   public object Clone() {...}  
}  
</pre>the ICloneable.Clone member of C becomes the implementation of Clone in ICloneable because explicit interface member implementations take precedence over other members. end example]</span> </span><span class="locator">
     Paragraph 6</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P6S1"></a>If a class or struct implements two or more interfaces containing a member with the same name, type, and parameter types, it is possible to map each of those interface members onto a single class or struct member.</span> </span><span class="paragraph"><span class="example">[Example: For example <pre class="code-example">
interface IControl  
{  
   void Paint();  
}  
interface IForm  
{  
   void Paint();  
}  
class Page: IControl, IForm  
{  
   public void Paint() {...}  
}  
</pre></span></span><span class="paragraph"><span class="example">Here, the Paint methods of both IControl and IForm are mapped onto the Paint method in Page. It is of course also possible to have separate explicit interface member implementations for the two methods. end example]</span> </span><span class="locator">
     Paragraph 7</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P7S1"></a>If a class or struct implements an interface that contains hidden members, then some members must necessarily be implemented through explicit interface member implementations.</span> <span class="example">[Example: For example <pre class="code-example">
interface IBase  
{  
   int P { get; }  
}  
interface IDerived: IBase  
{  
   new int P();  
}  
</pre></span></span><span class="paragraph"><span class="example">An implementation of this interface would require at least one explicit interface member implementation, and would take one of the following forms <pre class="code-example">
class C: IDerived  
{  
   int IBase.P { get {...} }  
   int IDerived.P() {...}  
}  
class C: IDerived  
{  
   public int P { get {...} }  
   int IDerived.P() {...}  
}  
class C: IDerived  
{  
   int IBase.P { get {...} }  
   public int P() {...}  
}  
</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>When a class implements multiple interfaces that have the same base interface, there can be only one implementation of the base interface.</span> <span class="example">[Example: In the example <pre class="code-example">
interface IControl  
{  
   void Paint();  
}  
interface ITextBox: IControl  
{  
   void SetText(string text);  
}  
interface IListBox: IControl  
{  
   void SetItems(string[] items);  
}  
class ComboBox: IControl, ITextBox, IListBox  
{  
   void IControl.Paint() {...}  
   void ITextBox.SetText(string text) {...}  
   void IListBox.SetItems(string[] items) {...}  
}  
</pre>it is not possible to have separate implementations for the IControl named in the base class list, the IControl inherited by ITextBox, and the IControl inherited by IListBox. Indeed, there is no notion of a separate identity for these interfaces. Rather, the implementations of ITextBox and IListBox share the same implementation of IControl, and ComboBox is simply considered to implement three interfaces, IControl, ITextBox, and IListBox. end example]</span> </span><span class="locator">
     Paragraph 9</span><span class="paragraph"><span class="sentence"><span class="sentence-number">1</span> <a name="P9S1"></a>The members of a base class participate in interface mapping.</span> <span class="example">[Example: In the example <pre class="code-example">
interface Interface1  
{  
   void F();  
}  
class Class1  
{  
   public void F() {}  
   public void G() {}  
}  
class Class2: Class1, Interface1  
{  
   new public void G() {}  
}  
</pre>the method F in Class1 is used in Class2's implementation of Interface1. end example]</span> </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 + -