<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 接口(C# 參考) 接口只包含[方法](https://msdn.microsoft.com/zh-CN/library/ms173114.aspx)、[屬性](https://msdn.microsoft.com/zh-CN/library/x9fsa0sw.aspx)、[事件](https://msdn.microsoft.com/zh-CN/library/awbftdfh.aspx)或[索引器](https://msdn.microsoft.com/zh-CN/library/6x16t2tx.aspx)的簽名。 實現接口的類或結構必須實現接口定義中指定的接口成員。 在下面的示例,類 ImplementationClass 必須實現一個不具有參數并返回 **void** 的名為 SampleMethod 的方法。 有關更多信息和示例,請參見[接口(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173156.aspx)。 ## 示例 ``` interface ISampleInterface { void SampleMethod(); } class ImplementationClass : ISampleInterface { // Explicit interface member implementation: void ISampleInterface.SampleMethod() { // Method implementation. } static void Main() { // Declare an interface instance. ISampleInterface obj = new ImplementationClass(); // Call the member. obj.SampleMethod(); } } ``` 接口可以是命名空間或類的成員,并且可以包含下列成員的簽名: * [方法](https://msdn.microsoft.com/zh-CN/library/ms173114.aspx) * [屬性](https://msdn.microsoft.com/zh-CN/library/w86s7x04.aspx) * [索引器](https://msdn.microsoft.com/zh-CN/library/2549tw02.aspx) * [事件](https://msdn.microsoft.com/zh-CN/library/8627sbea.aspx) 一個接口可從一個或多個基接口繼承。 當基類型列表包含基類和接口時,基類必須是列表中的第一項。 實現接口的類可以顯式實現該接口的成員。 顯式實現的成員不能通過類實例訪問,而只能通過接口實例訪問。 有關顯式接口實現的更多詳細信息和代碼示例,請參見[顯式接口實現(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173157.aspx)。 ## 示例 下面的示例演示了接口實現。 在此示例中,接口包含屬性聲明,類包含實現。 實現 IPoint 的類的任何實例都具有整數屬性 x 和 y。 ``` interface IPoint { // Property signatures: int x { get; set; } int y { get; set; } } class Point : IPoint { // Fields: private int _x; private int _y; // Constructor: public Point(int x, int y) { _x = x; _y = y; } // Property implementation: public int x { get { return _x; } set { _x = value; } } public int y { get { return _y; } set { _y = value; } } } class MainClass { static void PrintPoint(IPoint p) { Console.WriteLine("x={0}, y={1}", p.x, p.y); } static void Main() { Point p = new Point(2, 3); Console.Write("My Point: "); PrintPoint(p); } } // Output: My Point: x=2, y=3 ``` ## C# 語言規范 有關詳細信息,請參閱 [C# 語言規范](https://msdn.microsoft.com/zh-CN/library/ms228593.aspx)。該語言規范是 C# 語法和用法的權威資料。 ## 請參閱 [C# 參考](https://msdn.microsoft.com/zh-CN/library/618ayhy6.aspx) [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [C# 關鍵字](https://msdn.microsoft.com/zh-CN/library/x53a06bb.aspx) [引用類型(C# 參考)](https://msdn.microsoft.com/zh-CN/library/490f96s2.aspx) [接口(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173156.aspx) [使用屬性(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/w86s7x04.aspx) [使用索引器(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/2549tw02.aspx) [class(C# 參考)](https://msdn.microsoft.com/zh-CN/library/0b0thckt.aspx) [struct(C# 參考)](https://msdn.microsoft.com/zh-CN/library/ah19swz4.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>

                              哎呀哎呀视频在线观看