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

Variable = Variable? (re post)

Ron
I re posted beacause I copied and pasted my code incorrectly that it
probably needed a re start with the correct code. I also striped out the
Clone() stuff because that really had no bearing on the problem Im haveing.
My goal is to overwrite the Group object in the collection with the one that
is passed in the method. For some reaseon it doesnt overrite it. But I
tested by just assiging the 'Name' property instead of overwriting he entire
object and it worked; Everytime I use the object afterwards it has the new
name. The second example where the object is complete overwritin doesn't
work I can't understand why.

NOTE: this method resides in the Global.asax.

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group.Name = e.Group.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = e.Group;
}
}
Nov 19 '05 #1
3 1499
The problem is that 'group' is just a variable. The variable points to an
oject in memory.

All your code doing in example #2 is point 'group' to a different location
in memory. The place it originally pointed to still exists, and still has
its data. It has no bearing on that object. In fact, something in the
collection is still pointing to this object in memory.

So now you have 'group' and 'e.Group' pointing to the same object in memory.
That object only exists once.

The collection remains unchanged (unless e.Group happens to be pointing to
one of the groups in it).

I recommend you read up on how objects and references work, and how value
types work, and the difference between the 2.

"Ron" <ve*******@nospam.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl...
I re posted beacause I copied and pasted my code incorrectly that it
probably needed a re start with the correct code. I also striped out the
Clone() stuff because that really had no bearing on the problem Im haveing.
My goal is to overwrite the Group object in the collection with the one
that is passed in the method. For some reaseon it doesnt overrite it. But
I tested by just assiging the 'Name' property instead of overwriting he
entire object and it worked; Everytime I use the object afterwards it has
the new name. The second example where the object is complete overwritin
doesn't work I can't understand why.

NOTE: this method resides in the Global.asax.

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group.Name = e.Group.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = e.Group;
}
}

Nov 19 '05 #2
I'm certainly no c# expert, but is it a good idea to name your class
and your instance variable the same? Seems like in your second
example, the word "group" in the line "group = e.Group;" is a bit
indeterminate. Does it refer to the class or the instance? In the
first example, the fact that you are referring to a member probably is
enough of a clue.

Just a thought.

-Phil

Nov 19 '05 #3
Ron
Cool. I was under the impression that if I assigned the 'group' var with
the new group it would update the references like a chain.
So the collection would point to list[0] -> group -> new group.

As you pointed out thats not the case. I ended up adding a replace method
to my collection which would insert the new object and remove the old one.
Which works how i need it to.

Thanks!
Ron
"Ron" <ve*******@nospam.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl...
I re posted beacause I copied and pasted my code incorrectly that it
probably needed a re start with the correct code. I also striped out the
Clone() stuff because that really had no bearing on the problem Im haveing.
My goal is to overwrite the Group object in the collection with the one
that is passed in the method. For some reaseon it doesnt overrite it. But
I tested by just assiging the 'Name' property instead of overwriting he
entire object and it worked; Everytime I use the object afterwards it has
the new name. The second example where the object is complete overwritin
doesn't work I can't understand why.

NOTE: this method resides in the Global.asax.

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group.Name = e.Group.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = e.Group;
}
}

Nov 19 '05 #4

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

Similar topics

1
by: Robert | last post by:
Hello, I am using a simple HTML form to POST data to my credit-card provider. However, my credit-card provider has a limit on incoming variables. No variable can be greater than 256 bytes. ...
10
by: Tanteauguri | last post by:
Hi List, is there in python a variable variable like in PHP ($$var)? What I want to do is something like that: pc= for i in pc: i = anyclass() a.shutdown()
3
by: Sugapablo | last post by:
I would like to use variables in... for(q = 0; q < i; q++) { if(document.varArray1.varArray2.checked == TRUE) { alert("YES"); } else { alert("NO"); } }
9
by: mps | last post by:
Suppose..... arr = Array("only","a","test"); ArrayVar = "arr"; alert(ArrayVar); This the simplyfied version of my problem.. (alerting 'undefined' instead of 'only'...)
5
by: Ron | last post by:
I'm not really new to dotnet but am getting stumped by what I think is something easy. Any insights as to what i'm doing wrong? Thanks in advanced (see below) ------------------- This...
11
by: mfglinux | last post by:
Hello to everybody I would like to know how to declare in python a "variable name" that it is in turn a variable In bash shell I would wrote sthg like: for x in `seq 1 3` do M$i=Material(x)...
4
by: Hugh Oxford | last post by:
If I have an object property such as $obj->property_01 = 'blah' how do I access it using another variable $obj->fred = '01'; e.g. echo $obj->property_$obj->fred returns 'blah' I've tried...
1
by: thesmithman | last post by:
Hello, I have an array of data objects that I would like to send from my .swf to a server-side script. I would like to loop through the array and assign a variable key name to each name-value pair,...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.