在定義 subroutines 和 functions 時,可以利用 VB 提供的資料型別來定義參數,以及 function 回傳的型別 | Sub DoSomething(ByVal strValue1 As String, ByVal intCount As Integer, ByRef strValue2 As String = "初始內容") Function DoSomething(ByVal strValue1 As String, ByVal intCount As Integer, ByRef strValue2 As String = "初始內容") As String |
你可以利用 Optional 關鍵字來定義可以選擇性輸入的參數,但因為 Visual Basic.NET 不再支援 IsMissing 關鍵字,所以一定要給預設值。
| Function DoSomething(ByVal strValue1 As String, ByVal intCount As Integer, ByRef strValue2 As String = "初始內容" _ Optional ByVal strType = "預設內容" As String) As String |
|