vijay channe
what is call by value and call by reference ?
By vijay channe in ASP.NET on Mar 27 2010
  • Satyapriya Nayak
    Apr, 2010 3

    The ByVal keyword indicates that an argument is passed in such a way that the called procedure or property cannot change the value of a variable underlying the argument in the calling code.

    The ByRef keyword indicates that an argument is passed in such a way that the called procedure can change the value of a variable underlying the argument in the calling code.

    Example

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim x, y As Integer

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            x = 20
            y = 30
            MsgBox("original value=" & x & "  " & y)
            change1(x)
            change2(y)
            MsgBox("changed value=" & x & "  " & y)
        End Sub
        Sub change1(ByVal x As Integer)
            x = x + 10
        End Sub
        Sub change2(ByRef y As Integer)
            y = y + 10
        End Sub
    End Class

    Output
    original value = 20,30
    changed  value = 20,40

    • 0
  • Sadaqat Hussain
    Apr, 2010 2

    By value means a variable or object is having copy of value and by reference mean having only address of value.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS