|
-
Apr 30th, 2004, 02:44 PM
#1
Thread Starter
Fanatic Member
ByVal / ByRef Question
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?
-
Apr 30th, 2004, 05:47 PM
#2
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.. ), but I'm pretty convinced.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Apr 30th, 2004, 06:24 PM
#3
PowerPoster
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.. ), 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).
-
Apr 30th, 2004, 07:21 PM
#4
PowerPoster
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???
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 30th, 2004, 09:30 PM
#5
PowerPoster
.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
-
May 3rd, 2004, 06:23 AM
#6
Thread Starter
Fanatic Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|