I need to check whether the current object Is a specific class,
For example :
function a(b as object)
Why?
Bear with me: It's not as silly a question as it sounds; it depends on
what you want to /do/ with it once you've found it.
(1) If you want a method that, say, enables or disables the control that
you pass to it, but you want it to work for lots of different Types of
Control (contrived, but a common thing to do), use overloading:
Function Z( byval btn as Button, byval enabled as Boolean )
Function Z( byval tb as TextBox, byval enabled as Boolean )
Function Z( byval cmb as ComboBox, byval enabled as Boolean )
When you code
Z( Me.Button3 )
the compiler works out /which/ method to call.
(2) If you need to work out what Type of control you've got in, say, an
Event Handler, use TypeOf:
Sub Thing_Click( byval sender as Object, byval e as EventArgs ) _
Handles ...
If TypeOf sender Is TextBox Then
With DirectCast( sender, textBox )
. . .
End With
End If
End Sub
If you're testing for lots of Types, you still need a chain of If ..
Else's; you can't use TypeOf with Select .. Case.
(3) If you need to detect subclasses of a given Type, things get a bit
more fiddly:
If thing.GetType().IsSubClassOf( SomeType ) Then
' thing is a subclass of SomeType
' but not SomeType itself.
. . .
End If
HTH,
Phill W.