【IT168技术文档】
VB.net代码如下:public interface IConfigInfo { } public class A : IConfigInfo { } public class b { void bb(IConfigInfo a) { Type t = a.GetType(); } }
请大家注意红色部分,其中C#代码运行正常,而vb的哪个就是不行,错误原因为: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
a.GetType() 提示:GetType不是IConfigInfo 的成员
把a 先转成object试试.
这样子竟然行了。。。。极度郁闷,为什么c#中可以用a.gettype()来获取对象类型,而在vb中不行呢?Dim t As Type = ctype(a,object).GetType()