[2.0] Object References Oddity
I'm doing a side-application from my main project.
I have two Structs
structAnimation
which holds List<structFrames>Frames
When I add structAnimation to a hashtable, then add some structFrames to my Frames list.. whenever I go back to call the instance from a hashtable, the new changes aren't there! I have to re-add it to the hashtable to get it to update.
Very weird. I'm wondering what the deal is. This project has had a few other oddities going on. I'm practically doing the same things as my main project, but i'm getting odd results now and then
Re: [2.0] Object References Oddity
Something somewhere is deleting or changing that values. Those sort of problems you have to trace to find out exactly when and why it is changing. Are you sure it's changing the values in the first place? - Jennifer
Re: [2.0] Object References Oddity
It's one of the major differences between classes and structs in C#. classes are reference types; structs are value types. I would wager that when you add a structure to a hashtable, you add a copy, not a reference. If you want to see this behavior, you should try using a class instead of a struct.
Hope this helps.
Re: [2.0] Object References Oddity
I changed them to classes, and it still seems to do the same thing.
The weird thing is, only SOME values aren't being saved, rather than everything not being saved.
One of my classes I read an XML file and throw in some widths/heights/X/Y values.. All of them read properly, and if I walk through it, everything is correct. But once it gets out of my XML reading function.. some values don't get saved.
I create about 6 classes.. after i parse the XML, I attempt to read the values and the last frame's HEIGHT value isn't correct.. it's just the old value (whatever variable was before).. So it's as if it's not getting set, despite that it IS getting set, according to the debugging.
I'm walked through and I havn't found anything that is changing the value, either. Everytime I load it though, it's always the same instance and same height causing the problem... can't find anything
Re: [2.0] Object References Oddity
A structure shouldn't have a member that's a List. Structures are supposed to be simple types. You should definitely be using a class.
If you have multiple references to the same object and make changes through one of those references then the other will reflect those changes because they both refer to the same object. For instance, if your mother puts on a red dress and then your father checks what his wife is wearing, he's gonna find a red dress. There's no way it can be otherwise because "your mother" and "your father's wife" refer to the same person (or maybe not, but you get the idea). Reference types in .NET are exactly the same, so if you're using an instance of a class then you absolutely must be seeing this behaviour. If it doesn't appear that you are then it must be because you're doing something wrong in your code. Show us the code you're using when this situation arises and we'll see if we can see the issue.
Re: [2.0] Object References Oddity
Found it. A friend looked over my code and found it. When you type in a textbox, it updates the variables. However, whenever i update the textboxes with the variables, the textboxes were updating and resetting the variables.
Fixed now ;) thanks