473,804 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1139
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******** ******@TK2MSFTN GP12.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.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 205.141.32.1
| Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP12 .
phx.gbl
| Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:174211
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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
19190
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
38
5096
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 out what i'm doing wrong, and so far it seems i'm doing it the right way. Here's my code...any suggestions would be appreciated. <script language="javascript"> <!-- window.open("256fx/index.htm", "", "height=400, width=600"); //-->
7
2678
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 true (not necessarily an internal compiler error, but still an error) This may just a bit OT, but I decided to post it here instead of Microsoft because my question is more directed towards standards... Of course, any other day I would have...
9
1972
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 string object whose value is passed as a parameter to a function. The reference is pointing back to memory allocated on the heap where the contents of the string lives. Inside the function, I adjust the value, say string += "value", which means on...
4
3119
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 it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
8
995
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
7907
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.. (After reading that
2
1101
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 service and set the URL behavior to dynamic, all the settings are stored in the designer vb code. I can't seem to find a way to set everything up so that the address of the referenced web service can be edited in some config file. Long story...
7
1397
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 earlier post, instead of maintaining a flag, I'm unsubscribing to this eventHandler. My question is, why is this functional: this.Activated -= new System.EventHandler(Form1_Activated); instead of:
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.