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

object reference assignment doesn't update object in session

TS
I was under the impression that when you get a reference to an object, then
update that reference, the object gets updated. Apparently this isn't the
case using session?

code (note at this point this session object is null):
---------------------------------------------------------------------------
object o = Session["TheYearDataSet"];

if(o == null)
{
o = oh.FillTheYearDataSet(CISYear.ToString());
}
---------------------------------------------------------------------------

At this point, i would think that Session["TheYearDataSet"] would be the
same value as o, but it is still null even though o is now set. I thought
that o is just a reference to that object, and in changing the reference,
you change the object you are referencing????

thanks
Nov 17 '05 #1
7 2546
No, because there are 2 places in memory. There is Session["TheYearDataSet"]
which can point to an object. And there is 'o', which can also point to it.
Just because o points to one - doesn't mean your session variable will too.

It's not as if they are both aliases for the same reference variable - which
would be the only way this could work.

They are two completely different variables, that can point to different
objects. Or they can point to the same object. But if you change where one
of them points, that has no effect on the other.

"TS" <ma**********@nospam.nospam> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
I was under the impression that when you get a reference to an object, then
update that reference, the object gets updated. Apparently this isn't the
case using session?

code (note at this point this session object is null):
---------------------------------------------------------------------------
object o = Session["TheYearDataSet"];

if(o == null)
{
o = oh.FillTheYearDataSet(CISYear.ToString());
}
---------------------------------------------------------------------------

At this point, i would think that Session["TheYearDataSet"] would be the
same value as o, but it is still null even though o is now set. I thought
that o is just a reference to that object, and in changing the reference,
you change the object you are referencing????

thanks

Nov 17 '05 #2
"TS" <ma**********@nospam.nospam> wrote in
news:ui**************@TK2MSFTNGP12.phx.gbl:
I was under the impression that when you get a reference to an
object, then update that reference, the object gets updated.
Apparently this isn't the case using session?

code (note at this point this session object is null):
-----------------------------------------------------------------
---------- object o = Session["TheYearDataSet"];

if(o == null)
{
o = oh.FillTheYearDataSet(CISYear.ToString());
}
-----------------------------------------------------------------
----------

At this point, i would think that Session["TheYearDataSet"]
would be the same value as o, but it is still null even though
o is now set. I thought that o is just a reference to that
object, and in changing the reference, you change the object you
are referencing????


Session["TheYearDataSet"] is not an object. It is a reference to an
object, just like o.

The statement:

object o = Session["TheYearDataSet"];

makes o refer to the same object that Session["TheYearDataSet"] is
referring to.

Changing o to refer to a different object will have no effect on what
object Session["TheYearDataSet"] refers to.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #3
TS
this is true though, correct?

Textbox b;
Textbox a = b;
Textbox c = b;

a.Text = "good";

now, b.Text and c.Text both are "good"?

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
"TS" <ma**********@nospam.nospam> wrote in
news:ui**************@TK2MSFTNGP12.phx.gbl:
I was under the impression that when you get a reference to an
object, then update that reference, the object gets updated.
Apparently this isn't the case using session?

code (note at this point this session object is null):
-----------------------------------------------------------------
---------- object o = Session["TheYearDataSet"];

if(o == null)
{
o = oh.FillTheYearDataSet(CISYear.ToString());
}
-----------------------------------------------------------------
----------

At this point, i would think that Session["TheYearDataSet"]
would be the same value as o, but it is still null even though
o is now set. I thought that o is just a reference to that
object, and in changing the reference, you change the object you
are referencing????


Session["TheYearDataSet"] is not an object. It is a reference to an
object, just like o.

The statement:

object o = Session["TheYearDataSet"];

makes o refer to the same object that Session["TheYearDataSet"] is
referring to.

Changing o to refer to a different object will have no effect on what
object Session["TheYearDataSet"] refers to.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 17 '05 #4
"TS" <ma**********@nospam.nospam> wrote in
news:##**************@TK2MSFTNGP09.phx.gbl:
this is true though, correct?

Textbox b;
Textbox a = b;
Textbox c = b;

a.Text = "good";

now, b.Text and c.Text both are "good"?


Yes. But just to nitpick, the first line should be:

TextBox b = new TextBox();

One way of looking at this is there are four entities in your
code: a TextBox instance (created by the "new" statement),
and three references that point to that instance (a, b and c).

Since all of the references point to the same instance, the
following lines of code will all modify the same instance:

a.Text = "good";
b.Text = "good";
c.Text = "good";

Your original question was different. In it, you were changing
an object reference, not a property of the underlying instance.

Unfortunately, I can't find a good tutorial on object references
for C#. However, these parts of the documentation might help:

C# Language Specification - 1.2 Types:
http://msdn.microsoft.com/library/en...rpspec_1_2.asp

System.Object.ReferenceEquals
http://msdn.microsoft.com/library/de...qualstopic.asp

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #5
Yes, TS, the o = oh.FillTheYearDataSet(CISYear.ToString()); is changing o
to point to a newly created object returned by FillTheYearDataSet method.
But this has no effect on the Session["TheYearDataSet"];.

The text in your last example changed, because all the references (a,b,c)
point to the same instance of textbox. And the code a.Text = "good"; is NOT
changing a, b or c's reference. It is changing a member variable of the
TextBox.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #6
TS
thanks all, i have it now
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:xW*************@TK2MSFTNGXA01.phx.gbl...
Yes, TS, the o = oh.FillTheYearDataSet(CISYear.ToString()); is changing o
to point to a newly created object returned by FillTheYearDataSet method.
But this has no effect on the Session["TheYearDataSet"];.

The text in your last example changed, because all the references (a,b,c)
point to the same instance of textbox. And the code a.Text = "good"; is
NOT
changing a, b or c's reference. It is changing a member variable of the
TextBox.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #7
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #8

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

Similar topics

106
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
7
by: kon george | last post by:
Can somebody assist. I build this code on a dev laptop and copied across the entire code to a Windows 2003 server with 1.1 framework. It is basic ASP.NE T that uses web service for SQL Server...
3
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
11
by: syssyx | last post by:
I have a "CurrentUser" object in session that I want to access from each page of a vb.net website. I can successfully access everything if I include the following at the start of each pageload: ...
2
by: Jon Slaughter | last post by:
If I do something like $r = &$something; $r = array(); does it refer to $something or does the reference get remove first? if so(which it seems it is) can I for $r always ot point to...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.