Riddle me this:
Why is it that a method that accepts a ByVal textbox actually changes the textbox as if it was passed in ByRef? Are UI controls automatically ByRef?
Printable View
Riddle me this:
Why is it that a method that accepts a ByVal textbox actually changes the textbox as if it was passed in ByRef? Are UI controls automatically ByRef?
Hi.
As far as I now, Objects are always Byref, regardless of declaration, whereas Integer and string and the like depends on Byref and Byval.
Ofcourse, I may be wrong (It has happend before..:rolleyes: ), but I'm pretty convinced.
Quote:
Originally posted by pax
Hi.
As far as I now, Objects are always Byref, regardless of declaration, whereas Integer and string and the like depends on Byref and Byval.
Ofcourse, I may be wrong (It has happend before..:rolleyes: ), but I'm pretty convinced.
Yes, the textbox control is a reference type. Also, not a big deal, but, a string is a reference type. Many of the type's methods are overloaded to make is seem like a value type. This is why you read and hear so often that it is expensive to build strings (concatenation).
HI,
"As far as I now, Objects are always Byref, regardless of declaration, whereas Integer and string and the like depends on Byref and Byval"
I thought variables ARE objects???
.NET Types are split up into two categories:
- Reference Types
- Value Types
The difference between the two is where they are placed in memory. Value types are placed on the stack and reference types are placed on the managed heap, which is watched and cleaned-up by the garbage collector.
HTH
But a string is a reference type and I can pass that into a method ByVal and the original is not changed. Why does the original change for the textbox when passed in by val? Wouldn't it make a copy instead of another pointer to the same memory location?