interface解决命名冲突后的函数怎么用?

Jenf_Mu 2012-12-07 06:40:43
public interface IDoSomething
{
void Test();
}
public interface IOther
{
string Test();
}

/// <summary>
///Class1 的摘要说明
/// </summary>
public class Class1 : IDoSomething, IOther
{
public Class1()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void Test()
{
throw new NotImplementedException("IDoSomething");
}

string IOther.Test()
{
return "IOther";
}

}


string IOther.Test()
{
return "IOther";
}
这里解决了命名冲突,但是客户端怎么用这个函数啊?


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 c = new Class1();
Response.Write(IOther.Test());
}
}
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
oN5GrzoN 2012-12-07
  • 打赏
  • 举报
回复
引用 4 楼 Jenf_Mu 的回复:
引用 2 楼 caozhy 的回复:(Class1 As IOther).Test(); 这个又让我想到另一个问题,就是,要是这个函数是static的怎么办?也就是不需要生成对象就可以调用。
http://stackoverflow.com/questions/259026/why-doesnt-c-sharp-allow-static-methods-to-implement-an-interface
threenewbee 2012-12-07
  • 打赏
  • 举报
回复
引用 4 楼 Jenf_Mu 的回复:
引用 2 楼 caozhy 的回复:(Class1 As IOther).Test(); 这个又让我想到另一个问题,就是,要是这个函数是static的怎么办?也就是不需要生成对象就可以调用。
想多了,static函数不能继承,不能实现接口。
Jenf_Mu 2012-12-07
  • 打赏
  • 举报
回复
引用 2 楼 caozhy 的回复:
(Class1 As IOther).Test();
这个又让我想到另一个问题,就是,要是这个函数是static的怎么办?也就是不需要生成对象就可以调用。
threenewbee 2012-12-07
  • 打赏
  • 举报
回复
(c As IOther).Test();
threenewbee 2012-12-07
  • 打赏
  • 举报
回复
(Class1 As IOther).Test();
oN5GrzoN 2012-12-07
  • 打赏
  • 举报
回复
http://www.cnblogs.com/Ivony/archive/2010/05/17/1737037.html

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧