首页 新闻 会员 周边 捐助

求接口使用getType的方法的问题

0
悬赏园豆:20 [已解决问题] 解决于 2007-12-28 21:37
<P>C#代码如下:<BR>&nbsp;&nbsp;&nbsp; public interface IConfigInfo<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public class A : IConfigInfo<BR>&nbsp;&nbsp;&nbsp; {</P> <P>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public class b<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void bb(IConfigInfo a)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT color=#ff0000><STRONG>Type t = a.GetType();</STRONG></FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }</P> <DIV>VB.net代码如下:<BR>Public Interface IConfigInfo <BR>End Interface <BR>Public Class A <BR>&nbsp;&nbsp;&nbsp; Implements IConfigInfo <BR>&nbsp;&nbsp;&nbsp; <BR>End Class <BR>Public Class b <BR>&nbsp;&nbsp;&nbsp; Private Sub bb(ByVal a As IConfigInfo) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRONG><FONT color=#ff0000>Dim t As Type = a.GetType()</FONT></STRONG> <BR>&nbsp;&nbsp;&nbsp; End Sub <BR>End Class </DIV> <DIV>请大家注意红色部分,其中C#代码运行正常,而vb的哪个就是不行,错误原因为:</DIV> <DIV><STRONG><FONT color=#ff0000>a.GetType()</FONT></STRONG> 提示:GetType不是IConfigInfo 的成员,求助大家解决办法</DIV>
没剑的主页 没剑 | 菜鸟二级 | 园豆:430
提问于:2007-12-27 16:14
< >
分享
最佳答案
0
如果你不想转的话你在可以在接口里定义GetType方法,,, 好久没用vb了,刚才还想在vb里试试的,不过却发现vs里竟然没选装vb,晕
Dev.Hong | 菜鸟二级 |园豆:415 | 2007-12-27 16:55
其他回答(4)
0
把a 先转成object试试.
沙加 | 园豆:3680 (老鸟四级) | 2007-12-27 16:23
0
好久没用VB,不记得了
Birdshover | 园豆:352 (菜鸟二级) | 2007-12-27 17:29
0
在VB.NET中,接口不能从Object类中获取内容
Anders Cui | 园豆:1570 (小虾三级) | 2007-12-27 18:37
0
Dim o As Object = i Dim t As Type = o.GetType 这个估计是编译器问题,在VB里面隐藏了接口的基类,认为接口没有Gettype方法。 所以,只能用Object包装一下在用了
G yc {Son of VB.NET} | 园豆:2006 (老鸟四级) | 2007-12-27 19:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册