<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 接口中的索引器(C# 編程指南) 索引器可在 [接口(C# 參考)](https://msdn.microsoft.com/zh-CN/library/87d83y5b.aspx) 上聲明。接口索引器的訪問器與[類](https://msdn.microsoft.com/zh-CN/library/0b0thckt.aspx)索引器的訪問器具有以下方面的不同: * 接口訪問器不使用修飾符。 * 接口訪問器沒有體。 因此,訪問器的用途是指示索引器是讀寫、只讀還是只寫。 以下是接口索引器訪問器的示例: ``` public interface ISomeInterface { //... // Indexer declaration: string this[int index] { get; set; } } ``` 一個索引器的簽名必須區別于在同一接口中聲明的其他所有索引器的簽名。 下面的示例顯示如何實現接口索引器。 ``` // Indexer on an interface: public interface ISomeInterface { // Indexer declaration: int this[int index] { get; set; } } // Implementing the interface. class IndexerClass : ISomeInterface { private int[] arr = new int[100]; public int this[int index] // indexer declaration { get { // The arr object will throw IndexOutOfRange exception. return arr[index]; } set { arr[index] = value; } } } class MainClass { static void Main() { IndexerClass test = new IndexerClass(); System.Random rand = new System.Random(); // Call the indexer to initialize its elements. for (int i = 0; i < 10; i++) { test[i] = rand.Next(); } for (int i = 0; i < 10; i++) { System.Console.WriteLine("Element #{0} = {1}", i, test[i]); } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } } /* Sample output: Element #0 = 360877544 Element #1 = 327058047 Element #2 = 1913480832 Element #3 = 1519039937 Element #4 = 601472233 Element #5 = 323352310 Element #6 = 1422639981 Element #7 = 1797892494 Element #8 = 875761049 Element #9 = 393083859 */ ``` 在上例中,可以通過使用接口成員的完全限定名來使用顯式接口成員實現。例如: ``` public string ISomeInterface.this { } ``` 但是,只有當類使用同一索引器簽名實現一個以上的接口時,為避免多義性才需要使用完全限定名。例如,如果 Employee 類實現的是兩個接口 ICitizen 和 IEmployee,并且這兩個接口具有相同的索引器簽名,則必須使用顯式接口成員實現。即,以下索引器聲明: ``` public string IEmployee.this { } ``` 在 IEmployee 接口上實現索引器,而以下聲明: ``` public string ICitizen.this { } ``` 在 ICitizen 接口上實現索引器。 ## 請參閱 [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [索引器(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/6x16t2tx.aspx) [屬性(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/x9fsa0sw.aspx) [接口(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173156.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看