dummy question :-)

  • Thread starter Thread starter Luis Arvayo
  • Start date Start date
L

Luis Arvayo

Hi,

How do I compare if two variables are the same instance of a class ?

Example

dim instance1 = New MyClass
....
dim instance2 = instance1
.... or
dim instance2 = New MyClass
.....
'Now compare if the two instance are the same

If instance1 = instance2 Then
....
End If

The above syntax does not compile.

Thanks In Advance
Luis
 
Luis Arvayo said:
dim instance1 = New MyClass
...
dim instance2 = instance1
... or
dim instance2 = New MyClass
....
'Now compare if the two instance are the same

If instance1 = instance2 Then
...
End If

The above syntax does not compile.

Use the 'Is' operator instead of '='.

\\\
If instance1 Is Instance2 Then
...
End If
///
 
You can use the IS operator to compare identity

Dim A as new Widget
Dim B as new Widget
Dim C as Widget = A


(A is B) = false
(A is C) = true


A.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top