custvalidator: why is args byval and not byref?

X

xamman

the handler declaration:

CustomValidator1_ServerValidate(ByVal source As System.Object, ByVal
args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate

the question:

if in this sub i am to set args.IsValid to true or false depending on
my custom validator code,
why is args declared BYVAL? shouldnt it be BYREF to allow read & write?

thanks & merry christmas
 
M

Marina Levit [MVP]

You don't understand the concept of byval and byref.

For an object, byval means a copy of the *reference* the object is made. So
even though you have a copy of the reference, you don't have a copy of the
object. The copy of the reference to the object, still points to the same
single object. You can change where the reference copy points to - that does
not change the fact that the original reference, still points where it
pointed before.

Byref means the reference itself is passed in. Meaning, you can change where
the reference points to, and the original variable containing the reference
will now change where it points to as well.

The latter functionality is very rarely needed. Most of the time you just
care about accessing the object and its properties - and you have no need to
change where the reference points to.

Hence, things are ByVal by default, that is all you need most of the time,
and it is true for your scenario as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top