我有一个函数,当我调用它时,它让我不用 (),为什么?
Public Class Socio
Private _antiguedad As Integer
Public Function RetornarAntiguedad() As Integer
Return _antiguedad
End Function
End Class
Sub Main()
Dim test = New Socio()
test.RetornarAntiguedad <--- This works even though it doesnt have (), why?
Console.ReadKey()
End Sub
它看起来像一个属性?它不会在函数和属性之间产生混淆吗?
在 VB 语法中,函数调用()
在捕获其返回值时不需要尾随。
在上面的示例中,您像调用方法一样调用函数,而不捕获其返回值。因此,Visual Studio IDE 应自动附加括号。
但是,如果您要将其更改为:
Dim test As New Socio()
Dim result as Integer = test.RetornarAntiguedad
...不再需要括号。
这只是 VB.NET 语法,仅此而已。没什么好担心的。您的代码仍然有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句