zoukankan      html  css  js  c++  java
  • 显式接口成员实现

    类或结构可以通过使用显示接口实现来避免将成员声明为 public. 显示接口成员实现使用完全限定的接口成员名。例如 EidtBox类可以使用显示接口成员实现来实现IControl的Paint方法和IDataBind的Bind方法。

       1:      public class Binder
       2:      {
       3:          //
       4:      }
       5:      public interface IControl
       6:      {
       7:          void Paint();
       8:      }
       9:      public interface IDataBind
      10:      {
      11:          void Bind(Binder b);
      12:      }
      13:      public class EditBox : IControl,IDataBind
      14:      {
      15:          #region IControl Members
      16:   
      17:          public void IControl.Paint()
      18:          {
      19:              throw new NotImplementedException();
      20:          }
      21:   
      22:          #endregion
      23:   
      24:          #region IDataBind Members
      25:   
      26:          public void IDataBind.Bind(Binder b)
      27:          {
      28:              throw new NotImplementedException();
      29:          }
      30:   
      31:          #endregion
      32:      }
    调用方法:
       1:          static void Main(string[] args)
       2:          {
       3:              IControl editBox = new EditBox();
       4:              editBox.Paint();//正确
       5:              EditBox edit = new EditBox();
       6:              edit.Paint();//错误,找不到方法
       7:          }
    http://www.kissit.com.cn/
  • 相关阅读:
    windows下安装php5.5的redis扩展
    redis常见命令
    HDU 5869 Different GCD Subarray Query
    WA时查错点
    HDU 3333 Turing Tree
    HDU 5868 Different Circle Permutation
    AcWing 272 最长公共上升子序列 (dp)
    中国计量大学现代科技学院第四届“中竞杯”程序设计校赛 I 题 (双端队列bfs / 优先队列bfs)
    AtCoder ARC 109 D (拆点 + 分类讨论)
    codeforces 1408D. Searchlights (暴力 + 前缀优化)
  • 原文地址:https://www.cnblogs.com/Junelee1211/p/2371548.html
Copyright © 2011-2022 走看看