如下的代码就是两个实现的示例://接口定义 interface IA { void a(); } //显示实现的接口类 class a : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } } //隐式实现的接口类 class b : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } }
//隐式实现的接口类应该这样把 class b : IA { void a() { throw new Exception("The method or operation is not implemented."); } }
上面的代码错了,不好意思,是这样的:/// <summary> /// 接口的定义 /// </summary> public interface IA { void a(); } /// <summary> /// 显式的实现 /// </summary> public class A : IA { public void a() { throw new Exception("The method or operation is not implemented."); } } /// <summary> /// 隐式的实现 /// </summary> public class B : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } }
//接口定义 interface IA { void a(); } //显示实现的接口类 class a : IA { void a() { throw new Exception("The method or operation is not implemented."); } } //隐式实现的接口类 class b : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } } 是这样么
using System ; interface ICanvas { void Paint(); } public class EditBox: ICanvas { public void Paint()//隐式-----1 { Console.WriteLine("Paint method is called!"); } void ICanvas.Paint()//显示-----2 { Console.WriteLine("ICanvas.Paint method is called!"); } } class Test { static void Main() { EditBox editbox = new EditBox(); editbox.Paint();//调用方法1 ((ICanvas)editbox).Paint();//显示实现接口需要类型转换,调用方法2 } }
/// <summary> /// 接口的定义 /// </summary> public interface IA { void a(); } /// <summary> /// 显式的实现 /// </summary> public class A : IA { public void a() { throw new Exception("The method or operation is not implemented."); } } /// <summary> /// 隐式的实现 /// </summary> public class B : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } } 写反了……
using System ; interface ICanvas { void Paint(); } public class EditBox: ICanvas { public void Paint()//隐式-----1 { Console.WriteLine("Paint method is called!"); } void ICanvas.Paint()//显示-----2 { Console.WriteLine("ICanvas.Paint method is called!"); } } ==== 比较下……
/// <summary> /// 接口的定义 /// </summary> public interface IA { void a(); } /// <summary> /// 显式的实现 //隐式的实现 /// </summary> public class A : IA { public void a() { throw new Exception("The method or operation is not implemented."); } } /// <summary> /// 隐式的实现 //显示的实现 /// </summary> public class B : IA { void IA.a() { throw new Exception("The method or operation is not implemented."); } } 这个写反了才是关键……
using System;interface IA { void Paint(); } interface IB { void Paint(); } class SomeClass:IA,IB { void IA.Paint()//顯示接...解决重名问题 { Console.WriteLine("IA.Paint"); } void IB.Paint() { Console.WriteLine("IB.Paint"); } };public class Test { public static void Main() { IA a = new SomeClass(); a.Paint(); IB b = new SomeClass(); b.Paint(); Console.ReadLine(); } };
显示实现的接口,接口的成员都要声明成公用的(public)
而隐式实现的接口,接口的成员是接口类型加成员名称声明的。这样的声明可以通过强制转换进行和接品的转换。
interface IA
{
void a();
}
//显示实现的接口类
class a : IA
{ void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
//隐式实现的接口类
class b : IA
{ void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
class b : IA
{ void a()
{
throw new Exception("The method or operation is not implemented.");
}
}
/// 接口的定义
/// </summary>
public interface IA
{
void a();
}
/// <summary>
/// 显式的实现
/// </summary>
public class A : IA
{
public void a()
{
throw new Exception("The method or operation is not implemented.");
}
}
/// <summary>
/// 隐式的实现
/// </summary>
public class B : IA
{
void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
interface IA
{
void a();
}
//显示实现的接口类
class a : IA
{ void a()
{
throw new Exception("The method or operation is not implemented.");
}
}
//隐式实现的接口类
class b : IA
{ void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
是这样么
http://msdn2.microsoft.com/en-us/library/ms173157(VS.80).aspx
interface ICanvas
{
void Paint();
}
public class EditBox: ICanvas
{
public void Paint()//隐式-----1
{
Console.WriteLine("Paint method is called!");
}
void ICanvas.Paint()//显示-----2
{
Console.WriteLine("ICanvas.Paint method is called!");
}
}
class Test
{
static void Main()
{
EditBox editbox = new EditBox(); editbox.Paint();//调用方法1
((ICanvas)editbox).Paint();//显示实现接口需要类型转换,调用方法2
}
}
/// 接口的定义
/// </summary>
public interface IA
{
void a();
}
/// <summary>
/// 显式的实现
/// </summary>
public class A : IA
{
public void a()
{
throw new Exception("The method or operation is not implemented.");
}
}
/// <summary>
/// 隐式的实现
/// </summary>
public class B : IA
{
void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
写反了……
interface ICanvas
{
void Paint();
}
public class EditBox: ICanvas
{
public void Paint()//隐式-----1
{
Console.WriteLine("Paint method is called!");
}
void ICanvas.Paint()//显示-----2
{
Console.WriteLine("ICanvas.Paint method is called!");
}
}
====
比较下……
对不起了,我上面正好把显示及隐式实现说反了,真的很抱歉。在这里占用了楼主的宝地说了太多的话了,真是不好意思。我想楼主的问题可能也更清楚了。我收了:)
LZ以后这样的问题自己查下MSDN就可以了……
别问了!
/// 接口的定义
/// </summary>
public interface IA
{
void a();
}
/// <summary>
/// 显式的实现 //隐式的实现
/// </summary>
public class A : IA
{
public void a()
{
throw new Exception("The method or operation is not implemented.");
}
}
/// <summary>
/// 隐式的实现 //显示的实现
/// </summary>
public class B : IA
{
void IA.a()
{
throw new Exception("The method or operation is not implemented.");
}
}
这个写反了才是关键……
所以我非常的希望这里能是一个和气的地方。因为大家都是“学生”嘛。
我经常生怕误导别人星抗得多,给人的直观印象是,阅历多,给出的参考答案应该更“权威”,
可是,星再多,也是人扛着啊,
回复出错是难免的,错了不要紧,及时纠正就是,很多时候也是能力所不能及,
只要我们不去误导其他人Good Luck!
责任确实增大了,但是不能说是为了分而故意“误导”谁,相信大家也都不会这么做的,也没有谁敢保证自己说了就一定对的~~Ivony(授人以鱼不如授人以渔,上海谋生)
hbxtlhx(平民百姓-自已动手,丰衣足食)
哪一个帐户不是忽悠了若干板块——让多少人得到了帮助的老家伙了??
要我说,一人踢屁股一脚,呵呵~~——有本事来烟台,咱们喝扎啤比高低才是王道~~
{
void Paint();
}
interface IB
{
void Paint();
}
class SomeClass:IA,IB
{
void IA.Paint()//顯示接...解决重名问题
{
Console.WriteLine("IA.Paint");
}
void IB.Paint()
{
Console.WriteLine("IB.Paint");
}
};public class Test
{
public static void Main()
{
IA a = new SomeClass();
a.Paint();
IB b = new SomeClass();
b.Paint();
Console.ReadLine();
}
};
不是人家说你, 你第一次发贴发两个一模一样的例子, 第二次又发反, 不是想指责你技术不行, 而是态度不行, 第一次发重复时, 只要发贴前稍微看一眼就会发现, 更甚者是第二次, 既然已经错了一次了, 第二次应该认真检查后再发才是, 你如此粗心, 可以认为是在以灌水的心态在回贴. 楼主问的属于基本问题, 回答错不如不回答, 既然回答别人的问题, 就应该负责任不是, 说自己水平问题, 纯属狡辩, 既然自己都不会, 为什么去回答别人??
而且人家第一次说你, 并不算用词过分, 是你先用"暗算" 这样尖刻的词挑起争吵, 所以鄙人认为, 你应该为自己的态度道歉.
非常谢谢
其实我觉得你最后的那个回复说得就不对了.因为在hbxtlhx 第一次回复时就是这样说的"接口的实现分显示和隐式两种。
显示实现的接口,接口的成员都要声明成公用的(public)
而隐式实现的接口,接口的成员是接口类型加成员名称声明的。这样的声明可以通过强制转换进行和接品的转换。"即是说,他一直都认为 "显示实现的接口,接口的成员都要声明成公用的(public)" ,当发现两个是例子是一样的时候,他心中还是认为"显示实现的接口,接口的成员都要声明成公用的(public)" ,所以发第二次例子时,当然就是那样了.
应该是平常太牛逼,呗人说一下太突然啦。
能马上回归平常心态,难得。赞一个。我懒,有问题就爱google哈哈。