VB与Java的等价物是什么;s instanceof和isInstance()?
本着这个问题的精神VB与Java的等价物是什么;s instanceof和isInstance()?,java,vb.net,reflection,introspection,instanceof,Java,Vb.net,Reflection,Introspection,Instanceof,本着这个问题的精神 在VB.NET中比较类类型的等效语句是什么?与您的链接问题类似的VB语句几乎相同: TypeOf obj Is MyClass Dim result As Boolean = obj.GetType().IsAssignableFrom(otherObj.GetType()) 您正在寻找类似于类型的?这仅适用于引用类型,而不适用于int/etc If TypeOf "value" Is String Then Console.WriteLine("'tis a
在VB.NET中比较类类型的等效语句是什么?与您的链接问题类似的VB语句几乎相同:
TypeOf obj Is MyClass
Dim result As Boolean = obj.GetType().IsAssignableFrom(otherObj.GetType())
您正在寻找类似于
类型的
?这仅适用于引用类型,而不适用于int/etc
If TypeOf "value" Is String Then
Console.WriteLine("'tis a string, m'lord!")
还是要比较两个不同的变量实例?也适用于ref类型:
Dim one As Object = "not an object"
Dim two As Object = "also not an object, exactly"
Dim three as Object = 3D
If one.GetType.Equals( two.GetType ) Then WL("They are the same, man")
If one.GetType Is two.GetType then WL("Also the same")
If one.GetType IsNot three.GetType Then WL("but these aren't")
如果不使用两个对象,也可以像这样使用gettype()
:
If three.GetType Is gettype(integer) then WL("is int")
如果您想查看某个对象是否是另一种类型的子类(并且在.net 3.5中):
但如果您想在早期版本中这样做,您必须将其翻转(看起来很奇怪)并使用:
所有这些都是编译的,所以如果没有,就去DL
If three.GetType.IsSubclassOf(gettype(Object)) then WL("it is")
If gettype(Object).IsAssignableFrom(three.GetType) Then WL("it is")