溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

參數(shù) ByVal 和 ByRef 區(qū)別

發(fā)布時間:2020-06-18 09:16:05 來源:網(wǎng)絡 閱讀:486 作者:圖ttt 欄目:編程語言
  1. ByVal 關(guān)鍵字的參數(shù)是值傳參,ByRef 關(guān)鍵字的參數(shù)是地址傳參。

  2. ByVal的參數(shù),是指定參數(shù)類型的值,不會改變傳參對象的原地址值;

    ByRef的參數(shù),是指定原地址入?yún)?,是直接使用原地址對象,如果在方法里修改該對象的話,原地址的對象值也會改變,使用時慎用。


    例子:


    Public Class Form4

        Private number As Integer = 1


        Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            test2(number)

           MsgBox(number)

            test(number)

            MsgBox(number)

        End Sub


        Private Sub test(ByVal num As Integer)

            num += 1

        End Sub


        Private Sub test2(ByRef num As Integer)

            num += 1

        End Sub

    End Class


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI