By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

Is Operator question

P: n/a
I'm a beginner to programming & have a Question with the Is operator
when used in a class; sorry for the elementary question.

I have created a Class "Person3", in my Module I
create three different objects from this class however when I call the
"Spouse" Property and pass one of my objects and test if they are of
the same reference I get a True value. My questions is why? I'm
passing a different instanced object? When I test the following in the
module I get false, why do I get a diffrent result in the object?
bResult = joe Is joe ' true
bResult = joe Is ann ' false
bResult = joe Is Ann2 ' false
Any Clarifications would greatly be appreciated. Thanks
Module Module1
Sub Main()
Dim Joe as New Person3("joe", "Smith")
Dim ann As New Person3("Ann", "Smith")
Dim Ann2 As New Person3("Ann2", "Smith")
' this is where my issue begins
joe.Spouse = ann
joe.Spouse = Ann2
End Sub
End Module
Public Class Person3
Dim m_Spouse As Person3
Public m_FirstName As String
Public m_LastName As String
Public Sub New(ByVal firstName As String, _
ByVal lastName As String)
Me.m_FirstName = firstName
Me.m_LastName = lastName
End Sub
End Sub Public WriteOnly Property Spouse() As Person3
Set(ByVal Value As Person3)
Dim b As Boolean
m_Spouse = Value
b = m_Spouse Is Value
Console.WriteLine("the boolean value is: " & b)
End Set
End Property
End Class

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
rSmtih <rS****@discussions.microsoft.com> wrote:
I'm a beginner to programming & have a Question with the Is operator
when used in a class; sorry for the elementary question.

I have created a Class "Person3", in my Module I
create three different objects from this class however when I call the
"Spouse" Property and pass one of my objects and test if they are of
the same reference I get a True value. My questions is why? I'm
passing a different instanced object? When I test the following in the
module I get false, why do I get a diffrent result in the object?
You're testing whether or not the spouse is the value which has just
been set:
End Sub Public WriteOnly Property Spouse() As Person3
Set(ByVal Value As Person3)
Dim b As Boolean
m_Spouse = Value
b = m_Spouse Is Value


Why would m_Spouse be different from Value, when you've just set
m_Spouse to be the same as Value?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

P: n/a
rSmith,

The IS operatar in VBNet is to check if an object is the same
dim a as bclass
dim c as bclass

If a IS c 'now equal because they are both empty (nothing)

a = new bclass
c = a
If a IS c 'they are still equal because they reference too the same object

c = new bclass
If a Is c 'they are now unequal because it are two different objects

I hope this helps?

Cor
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.