473,388 Members | 1,326 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,388 software developers and data experts.

Reference vs Value

This question seems almost too trivial and i feel i should know the answer
but alas...

I have a class called 'RandomObject'

I have an instance of the class...
dim Blah as new RandomObject.

I set a few properties on the class and so on and so forth.
Now i create a new reference to the class...
dim TemporaryBlah as new RandomObject

I set the temporary value to the initial value...
TemporaryBlah = Blah

Make some changes to Blah and then would like to return to my initial state
by setting blah to the temporary value...
Blah = TemporaryBlah

Of course since Blah and TemporaryBlah are references to a class, a
reference type, they actually do not contain the data but instead a
reference to the data so they are in fact the same thing... with all that
being said, how can i keep temporaryBlah static when i make the changes to
blah? I would basically like to treat the reference type like a value
type... is that possible?

:\\derian
Nov 20 '05 #1
3 1465
"derian" <--*******@astutesolutions.com---> wrote in news:ui6tMlCiDHA.1688
@TK2MSFTNGP10.phx.gbl:
how can i keep temporaryBlah static when i make the changes to
blah? I would basically like to treat the reference type like a value
type... is that possible?


You need to clone the object using the .clone/.copy methods (if available)
otherwise I think you need to implement the ICloneable Interface.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2
If it's your object that you created, (I do this a lot) I create a second
constructor (New) that takes a reference to its own type. Then I peel off
the values from the type into the new object.

You can also serialize to a memory stream if your object is serializable and
the deserialize to the new object.

"derian" <--*******@astutesolutions.com---> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
This question seems almost too trivial and i feel i should know the answer
but alas...

I have a class called 'RandomObject'

I have an instance of the class...
dim Blah as new RandomObject.

I set a few properties on the class and so on and so forth.
Now i create a new reference to the class...
dim TemporaryBlah as new RandomObject

I set the temporary value to the initial value...
TemporaryBlah = Blah

Make some changes to Blah and then would like to return to my initial state by setting blah to the temporary value...
Blah = TemporaryBlah

Of course since Blah and TemporaryBlah are references to a class, a
reference type, they actually do not contain the data but instead a
reference to the data so they are in fact the same thing... with all that
being said, how can i keep temporaryBlah static when i make the changes to
blah? I would basically like to treat the reference type like a value
type... is that possible?

:\\derian

Nov 20 '05 #3
it is my own object... sorry for not specifying!
i'll give that a shot and see what happens... thanks for the input guys.
"Justin Weinberg" <jw*******@bravopos.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
If it's your object that you created, (I do this a lot) I create a second
constructor (New) that takes a reference to its own type. Then I peel off
the values from the type into the new object.

You can also serialize to a memory stream if your object is serializable and the deserialize to the new object.

"derian" <--*******@astutesolutions.com---> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
This question seems almost too trivial and i feel i should know the answer but alas...

I have a class called 'RandomObject'

I have an instance of the class...
dim Blah as new RandomObject.

I set a few properties on the class and so on and so forth.
Now i create a new reference to the class...
dim TemporaryBlah as new RandomObject

I set the temporary value to the initial value...
TemporaryBlah = Blah

Make some changes to Blah and then would like to return to my initial

state
by setting blah to the temporary value...
Blah = TemporaryBlah

Of course since Blah and TemporaryBlah are references to a class, a
reference type, they actually do not contain the data but instead a
reference to the data so they are in fact the same thing... with all that being said, how can i keep temporaryBlah static when i make the changes to blah? I would basically like to treat the reference type like a value
type... is that possible?

:\\derian


Nov 20 '05 #4

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

Similar topics

26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
19
by: daniel | last post by:
This is a pretty basic-level question, but I'd really like to know, so thanks for any help or pointers you can provide (like what I would google for ;o) Suppose: <code> myFunc() {
6
by: Chris Simmons | last post by:
I know that a String is immutable, but I don't understand why this piece of code fails in nUnit: // BEGIN CODE using System; class Test { public static void Main( String args )
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
9
by: Edward Diener | last post by:
Can one use 'ref' ( or 'out' ) on a reference type to create a reference to a reference in C#. I know one can use it on a value type to create a reference to that value.
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.