技术开发 频道

关于接口使用getType的方法的问题


【IT168技术文档】

public interface IConfigInfo { } public class A : IConfigInfo { } public class b { void bb(IConfigInfo a) { Type t = a.GetType(); } }
  VB.net代码如下:
Public Interface IConfigInfo End Interface Public Class A Implements IConfigInfo End Class Public Class b Private Sub bb(ByVal a As IConfigInfo) Dim t As Type = a.GetType() End Sub End Class
  请大家注意红色部分,其中C#代码运行正常,而vb的哪个就是不行,错误原因为:
  a.GetType() 提示:GetType不是IConfigInfo 的成员
  把a 先转成object试试.
Dim t As Type = ctype(a,object).GetType()
  这样子竟然行了。。。。极度郁闷,为什么c#中可以用a.gettype()来获取对象类型,而在vb中不行呢?
0
相关文章