傳值 傳址 預設參數 (VB.NET)

傳值 傳址 預設參數 (VB.NET)

 

    Sub Main()

 

        Dim i As Integer = 21

 

        MySub(i)

 

        Console.WriteLine(i)

 

        MySub2(i)

 

        Console.WriteLine(i)

 

        MySub3(10)

 

        MySub3()

 

    End Sub


 

    Sub MySub(ByVal i As Integer)

 

        i += 1

 

    End Sub

 

    Sub MySub2(ByRef i As Integer)

 

        i += 1

 

    End Sub

 

    Sub MySub3(Optional ByRef i As Integer = 100) '預設值 100

 

        i += 1

 

        Console.WriteLine(i)

 

    End Sub


如有錯誤 歡迎指正