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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 如何:顯式實現接口成員(C# 編程指南) 本示例聲明一個 [接口](https://msdn.microsoft.com/zh-CN/library/87d83y5b.aspx)IDimensions 和一個類 Box,該類顯式實現接口成員 getLength 和 getWidth。通過接口實例 dimensions 訪問這些成員。 ``` interface IDimensions { float getLength(); float getWidth(); } class Box : IDimensions { float lengthInches; float widthInches; Box(float length, float width) { lengthInches = length; widthInches = width; } // Explicit interface member implementation: float IDimensions.getLength() { return lengthInches; } // Explicit interface member implementation: float IDimensions.getWidth() { return widthInches; } static void Main() { // Declare a class instance box1: Box box1 = new Box(30.0f, 20.0f); // Declare an interface instance dimensions: IDimensions dimensions = (IDimensions)box1; // The following commented lines would produce compilation // errors because they try to access an explicitly implemented // interface member from a class instance: //System.Console.WriteLine("Length: {0}", box1.getLength()); //System.Console.WriteLine("Width: {0}", box1.getWidth()); // Print out the dimensions of the box by calling the methods // from an instance of the interface: System.Console.WriteLine("Length: {0}", dimensions.getLength()); System.Console.WriteLine("Width: {0}", dimensions.getWidth()); } } /* Output: Length: 30 Width: 20 */ ``` ## 可靠編程 * 請注意 **Main** 方法中下列代碼行被注釋掉,因為它們將產生編譯錯誤。顯式實現的接口成員不能從[類](https://msdn.microsoft.com/zh-CN/library/0b0thckt.aspx)實例訪問: ``` //System.Console.WriteLine("Length: {0}", box1.getLength()); //System.Console.WriteLine("Width: {0}", box1.getWidth()); ``` * 還請注意,**Main** 方法中的下列代碼行成功輸出框的尺寸,因為這些方法是從接口實例調用的: ``` System.Console.WriteLine("Length: {0}", dimensions.getLength()); System.Console.WriteLine("Width: {0}", dimensions.getWidth()); ``` ## 請參閱 [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [類和結構(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173109.aspx) [接口(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms173156.aspx) [如何:顯式實現兩個接口的成員(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/4taxa8t2.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>

                              哎呀哎呀视频在线观看