bra*_*zoo 11 java vb.net reflection introspection instanceof
本着c#问题的精神..
在VB.NET中比较类类型的等价语句是什么?
And*_*ker 18
你在寻找类似的东西TypeOf
吗?这仅适用于引用类型,而不适用于int/etc.
If TypeOf "value" Is String Then
Console.WriteLine("'tis a string, m'lord!")
Run Code Online (Sandbox Code Playgroud)
或者您想比较两个不同的变量实例?也适用于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")
Run Code Online (Sandbox Code Playgroud)
gettype()
如果您不使用两个对象,也可以这样使用:
If three.GetType Is gettype(integer) then WL("is int")
Run Code Online (Sandbox Code Playgroud)
如果你想看看某些东西是否是另一种类型的子类(并且在.net 3.5中):
If three.GetType.IsSubclassOf(gettype(Object)) then WL("it is")
Run Code Online (Sandbox Code Playgroud)
但是如果你想在早期版本中这样做,你必须翻转它(看起来很奇怪)并使用:
If gettype(Object).IsAssignableFrom(three.GetType) Then WL("it is")
Run Code Online (Sandbox Code Playgroud)
所有这些都在SnippetCompiler中编译,如果你没有它,请去DL.
归档时间: |
|
查看次数: |
12615 次 |
最近记录: |