Thanks, pbuk. I got around whatever limitation kept me from passing the reference to the original string around by creating my own class.pbuk said:Yes that's right.
It's probably also worth mentioning that strings in C# are immutable: it is not possible to change their state. If you want to pass something to a function that modifies it then you can use the StringBuilder class.
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
34 replies · 5K views
Physics news on Phys.org
rbelli1
Gold Member
- 1,092
- 446
pbuk said:strings in C# are immutable
Drakkith said:limitation kept me from passing the reference to the original string
When you tried to change the "original string" somewhere else you didn't actually change it. you created a new string then assigned it to the "other" variable. The "original" happily hung out and was used for the tooltip.
BoB
Well that answers that. Thank you!rbelli1 said:When you tried to change the "original string" somewhere else you didn't actually change it. you created a new string then assigned it to the "other" variable. The "original" happily hung out and was used for the tooltip.
BoB
Oh I'm an idiot. From my own link in post #26:
Because a string "modification" is actually a new string creation, you must use caution when you create references to strings. If you create a reference to a string, and then "modify" the original string, the reference will continue to point to the original object instead of the new object that was created when the string was modified.
The explanation was right in front of me as soon as I found that page and I just missed it completely.
Because a string "modification" is actually a new string creation, you must use caution when you create references to strings. If you create a reference to a string, and then "modify" the original string, the reference will continue to point to the original object instead of the new object that was created when the string was modified.
The explanation was right in front of me as soon as I found that page and I just missed it completely.
- 13,808
- 16,626
Sounds familiar... <wry smile emoji>Drakkith said:The explanation was right in front of me as soon as I found that page and I just missed it completely.
Similar threads
C/C++ Why Isn't My C++ Function Passing By Reference Correctly?
- Colton0117
- · Replies 3 ·
- Programming and Computer Science
- Replies
- 3
C/C++ Pass by Reference Function Build Error
- Saladsamurai
- · Replies 2 ·
- Programming and Computer Science
- Replies
- 2
Moving Reference Frames: One Car Passing Another
- Kristenx2
- · Replies 1 ·
- Introductory Physics Homework Help
- Replies
- 1