在Visual Studio 2010 撰寫Visual Basic 10程式時,若定義多載方法時,函式簽名只有差在一個Optional 參數;
Module Module1
Sub Main()
Console.WriteLine(Add(10))
Console.WriteLine(Add(10, 20))
End Sub
Private Function Add(i As Integer) As Integer
Return i
End Function
Private Function Add(i As Integer, Optional j As Integer = 0) As Integer
Return i + j
End Function
End Module
Sub Main()
Console.WriteLine(Add(10))
Console.WriteLine(Add(10, 20))
End Sub
Private Function Add(i As Integer) As Integer
Return i
End Function
Private Function Add(i As Integer, Optional j As Integer = 0) As Integer
Return i + j
End Function
End Module
則編譯程式時,會出現錯誤
而在Visual Studio 11 Beta中 (Visual Basic 11),已經沒有這個限制了,當然程式也可以正常執行:
沒有留言:
張貼留言