无法实例化接口,不能有接口类型为 的对象。类可以实现接口,类可以实现实例化。 - Herfried K. Wagner MVP·VB Classic,VB.NET http://www.mvps。 org / dotnet This has been bugging me for a while now.GetType isn''t availble for variables decalred as interface types, I have toDirectCast(somevariable, Object).In example:Sub SomeSub(ByVal Dictionary as IDictionary)If Dictionary is Nothing Then ReturnDim o as Object = DirectCast(Dictionary, Object)If GetType(ISomeInterface).IsAssignableFrom(o.GetType ) Then''<... some code...>End IfEnd SubDoes this mean that it is possible to have variable types that are not derivedfrom Object? And if not, why aren''t all variables treated as Objects?Bob 解决方案The Interface does not have a GetType method.--ArminAn interface cannot be instantiated, there cannot be objects with the typeof an interface. Classes can implement interfaces and classes can getinstantiated.--Herfried K. WagnerMVP · VB Classic, VB.NET http://www.mvps.org/dotnet 这篇关于将GetType和变量声明为接口类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 20:47
查看更多