Visual Basic is a statement

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 find out if a node is the same type. Right now, I just drop it and see that the result is zero, but I want to use the "Is" operator.

+4
source share
2 answers

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

The Is operator determines whether references to two objects refer to the same object.

This will not indicate if the object is a particular type.

To compare types, you should use:

 If TypeOf node Is EquipmentNode Then 
+7
source

The Is statement in VB is not - like Is in C # - it checks if an object is of a particular type, it does the same job as C # ReferenceEquals() .

+2
source

Source: https://habr.com/ru/post/1438083/


All Articles