BC30577:“AddressOf”操作数必须是方法名(不带括号)

AddressOf 运算符创建引用特定过程的过程委托实例。 语法如下:

AddressOf procedurename

你在 AddressOf 之后的参数两侧插入了括号,但其中不需要任何内容。

错误 ID:BC30577

示例

下面的示例生成 bc30577:

Public Sub CountZeroToTen()
    For i = 0 To 10
        Console.WriteLine($"Counted: {i}")
        Threading.Thread.Sleep(500)
    Next
End Sub

Sub Main()
    ' Any of the following two lines generates bc30577.
    'Dim t As New Threading.Thread(AddressOf(CountZeroToTen))
    'Dim t As New Threading.Thread(AddressOf CountZeroToTen())
    t.Start()
End Sub

更正此错误

  1. 删除 AddressOf 后面参数两侧的括号,如下例所示:

    Public Sub CountZeroToTen()
        For i = 0 To 10
            Console.WriteLine($"Counted: {i}")
            Threading.Thread.Sleep(500)
        Next
    End Sub
    
    Sub Main()
        Dim t As New Threading.Thread(AddressOf CountZeroToTen)
        t.Start()
    End Sub
    
  2. 确保参数是方法名称。

另请参阅