close
自訂程序的多載係指程式中可建立多個相同名稱的自訂程序,執行時視其自訂程序內虛引數的引數個數或引數資料型別的不同來呼叫對應的自訂程序。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x, y, z As Integer
x = 50
y = 20
z = 80
Label1.Text = sum(x, y)
Label2.Text = sum(x, y, z)
End Sub
Function sum(ByVal x As Integer, ByVal y As Integer)
Return (x + y)
End Function
Function sum(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
Return (x + y + z)
End Function
End Class
全站熱搜