Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Basic - Is operator

Tags:

vb.net

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.

like image 767
contactmatt Avatar asked Jan 15 '23 09:01

contactmatt


2 Answers

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
like image 105
Reed Copsey Avatar answered Feb 02 '23 00:02

Reed Copsey


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().

like image 42
Joachim Isaksson Avatar answered Feb 01 '23 22:02

Joachim Isaksson