473,403 Members | 2,323 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,403 software developers and data experts.

Stupid question about object reference

Ok, if I have a class:

Public Class MyXClass
Public Property X as Integer
.....
End Class

In my code if I have two instances of this class:

Dim myX1 as new MyXClass
Dim myX2 as MyXClass

myX2 = myX1

Is myX2 a reference to the myX1 object or is it just a copy? In other words
if I modify the property within myX2, will it change myX1.

I believe it is a by reference situation but I could not find anything in
the MSDN documentation to confirm this. I"m sure its there, just don't know
exactly where.

STom
Nov 20 '05 #1
3 1098
There is no copy created, both variables point to the same instance of the
object. Creating a copy woudl bring up the question of whether or not it
should be a deep copy, if so, then you could be copying large sized objects,
etc.

Structures however, are copied. So if in your example these weren't
classes, but structures, there would be 2 instance of the structure, with
each variable having its own copy.

"STom" <st***********@hotmail.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
Ok, if I have a class:

Public Class MyXClass
Public Property X as Integer
....
End Class

In my code if I have two instances of this class:

Dim myX1 as new MyXClass
Dim myX2 as MyXClass

myX2 = myX1

Is myX2 a reference to the myX1 object or is it just a copy? In other words if I modify the property within myX2, will it change myX1.

I believe it is a by reference situation but I could not find anything in
the MSDN documentation to confirm this. I"m sure its there, just don't know exactly where.

STom

Nov 20 '05 #2
STom,

Your assumption is correct, in your code example myX1 and myX2 both point
to the same MyXClass object. Changes in myX1 can be seen in myX2; they both
reference the same object.
hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.
--------------------
| From: "STom" <st***********@hotmail.com>
| Subject: Stupid question about object reference
| Date: Mon, 19 Jan 2004 14:21:36 -0500
| Lines: 24
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <eb**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 205.141.32.1
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP12.
phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:174211
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Ok, if I have a class:
|
| Public Class MyXClass
| Public Property X as Integer
| ....
| End Class
|
| In my code if I have two instances of this class:
|
| Dim myX1 as new MyXClass
| Dim myX2 as MyXClass
|
| myX2 = myX1
|
| Is myX2 a reference to the myX1 object or is it just a copy? In other
words
| if I modify the property within myX2, will it change myX1.
|
| I believe it is a by reference situation but I could not find anything in
| the MSDN documentation to confirm this. I"m sure its there, just don't
know
| exactly where.
|
| STom
|
|
|

Nov 20 '05 #3
* "STom" <st***********@hotmail.com> scripsit:
Ok, if I have a class:

Public Class MyXClass
Public Property X as Integer
....
End Class

In my code if I have two instances of this class:

Dim myX1 as new MyXClass
Dim myX2 as MyXClass

myX2 = myX1

Is myX2 a reference to the myX1 object or is it just a copy? In other words
if I modify the property within myX2, will it change myX1.

I believe it is a by reference situation but I could not find anything in
the MSDN documentation to confirm this.


Keywords: Value types, Reference types.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
38
by: Shaun McKinnon | last post by:
HI...Here's my problem...I have a popup window that loads when i want it to, but it's not sized properly. I've set the size, but it doesn't seem to work. I've been on 8 different websites to find...
7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
9
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
8
by: KC | last post by:
From what little I understand about them, datasets are like mini-databases. If this is so, can I query tables in that dataset? What kind of object would I hold the result set in? Ken
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
2
by: =?Utf-8?B?RGF2ZSBU?= | last post by:
I have a business logic web service that references an object library. No problem there. This object library needs to reference a data access web service. If I add a web reference to the DAL web...
7
by: RvGrah | last post by:
I'm using the Activated event of my form to run a database query in a backroundWorker, and want to dismiss the call after the first time the form is activated. Based on some excellent advice in an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.