How do ByVal and ByRef behave when a VB.NET parameter refers to an object?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
ByVal copies the argument value into the parameter. For a reference type, that value is a reference, so the method can still mutate the same object, but reassigning the parameter does not replace the caller’s variable. ByRef allows the method to replace the caller’s variable as well. For value types, ByVal normally copies the value. Prefer retu ing a result or clear object methods when that makes changes easier to follow. Do not claim ByVal makes an object immutable or creates an independent deep copy.
Related Questions in Visual Basic
VB 6, COM, DCOM, Microsoft platform interview questions
Advanced level • 727 views
Visual Basic Interview questions
Advanced level • 643 views
Why should VB.NET file handling use a Using block?
Medium level • 3 views
In VB.NET, how do Sub and Function differ?
Easy level • 2 views
How would you validate integer input without using exceptions for an expected invalid value?
Medium level • 2 views