惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
L
LangChain Blog
B
Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
U
Unit 42
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
小众软件
小众软件
I
InfoQ
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
C
Check Point Blog

博客园 - 梅子黄时雨

离职反思 人际交往能力:远比你想象的重要 关于晋升 生产力提升计划 向企业一样的思考 在CentOS上搭建WordPress的博客系统 Some Useful LINQ Extension Methods MVC模式 IIS7.5配置 An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. C# 整数和byte数组互换 C#实现的堆栈 ASP.NET 验证控件 Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转) C#winform 配置webconfig 动态SQL EXEC DELL 1520 笔记本拆机 关于表变量 华为致新员工书
显式接口成员实现
梅子黄时雨 · 2012-02-28 · via 博客园 - 梅子黄时雨

类或结构可以通过使用显示接口实现来避免将成员声明为 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:          }