Friday, 9 August 2013

What is the Difference Between ByRef and ByVal

ByRef refers to the location – But if you pass using “ByRef” then if the parameter values are changed, then the original argument value is also modified. The ByRef use, would imply that a change performed by the statement of the value you pass, has an affect on the actual data. You pass an argument by reference by specifying the ByRef keyword for the corresponding parameter in the procedure definition. When you use this passing mechanism, compiler gives the procedure a direct reference to the underlying programming element in the calling code.
ByVal refers to the actual value – if you are passing parameters with “ByVal” then even if the parameter values are changed, the original argument values will remain intact. Selecting a ByVal would thereby mean you are only working on a copy or replica of the data, and not the actual data segment it self. You pass an argument by value by specifying the ByVal keyword for the corresponding parameter in the procedure definition. When you use this passing mechanism, Visual Basic copies the value of the underlying programming element into a local variable in the procedure. The procedure code does not have any access to the underlying element in the calling code

No comments:

Post a Comment