標題:
[發問]
傳值呼叫(Call By Value)
[打印本頁]
作者:
edchen70
時間:
2015-7-10 18:48
標題:
傳值呼叫(Call By Value)
下列是用call By Value的程式碼,顯示的數值是10,我想請問一下各位就是a沒有宣告,那a是x的複製值嗎?sub那邊不太了解?希望有先進解釋一下
Module Module1
Sub Main()
Dim x As Integer = 10
Call Square(x)
Console.WriteLine(x)
Console.ReadKey()
End Sub
Sub Square(ByVal a As Integer)
a = a ^ 2
End Sub
End Module
作者:
Min
時間:
2015-7-25 00:12
變數a 是有宣告喔!
Sub Square(ByVal a As Integer) '宣告a變數為數值,ByVal 則是無回傳值。
ex1
Sub Main()
Dim x As Integer = 10
Call Square(x)
msgbox.show(x)'還是10
End Sub
Sub Square(
ByVal
a As Integer)
a = a +a
End Sub
ex2
Sub Main()
Dim x As Integer = 10
Call Square(x)
msgbox.show(x)'回傳Square運算過的值,等於20。
End Sub
Sub Square(
Byref
a As Integer)
a = a +a
End Sub
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)