473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Is Operator question

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
2 1095
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
30
by: | last post by:
I have not posted to comp.lang.c++ (or comp.lang.c++.moderated) before. In general when I have a C++ question I look for answers in "The C++ Programming Language, Third Edition" by Stroustrup....
2
by: victor75040 | last post by:
Before you all start flaming me, I am not a student and this is not for any homework. Just someone learing c++ on their own. I am now up to the chapter in my book that describes operator...
2
by: wongjoekmeu | last post by:
Hello All, I have a question about a C++ listing that I don't understand from a book that I use to learn C++. In the listing a class String is declared and defined. The beginning look like this...
4
by: Mark Stijnman | last post by:
A while ago I posted a question about how to get operator behave differently for reading and writing. I basically wanted to make a vector that can be queried about whether it is modified recently...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
2
by: Harry | last post by:
Hi all, I am writing a logger program which can take any datatype. namespace recordLog { enum Debug_Level {low, midium, high}; class L { std::ofstream os; Debug_Level cdl; const...
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
18
by: Ranganath | last post by:
Why is throw keyword considered as an operator?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.