G
Guest
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
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