contactmatt
contactmatt

Reputation: 18610

Visual Basic - Is operator

Public Class EquipmentNode
 '...
End Class

Private Sub DoWork()
 Dim node As TreeNode = _contextNode

 If node is EquipmentNode ' Does not work
 if node is TypeOf EquipmentNode ' Does not work
End Sub

How can I see if the node is the same type. Right now I'm just casting it and seeing if the result is null, but I want to make use of the "Is" operator.

Upvotes: 4

Views: 843

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 180927

The Is operator in VB doesn't - as is in C# - check if an object is of a certain type, it does the same job as C#'s ReferenceEquals().

Upvotes: 2

Reed Copsey
Reed Copsey

Reputation: 564441

The Visual Basic Is Operator, (unlike the C#'s is operator), does not tell you about the object's type, but rather whether two objects variables refer to the same actual object instance.

The Is operator determines if two object references refer to the same object

This will not tell you whether the object is a specific type.

To compare types, you'd use:

If TypeOf node Is EquipmentNode Then

Upvotes: 7

Related Questions