C#相当于VB.Net AddressOf Operator

时间:2013-12-06 16:02:41

标签: c# vb.net

代码:

public Thread ThreadReceive;

ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages)
        ThreadReceive.Start()


    Public Sub ReceiveMessages()
        Try
            Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
            txtIP.Text = RemoteIpEndPoint.Address.ToString
            Dim BitDet As BitArray
            BitDet = New BitArray(receiveBytes)
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try
    End Sub

任何人都可以建议我如何转换这一行:

ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages)

vb到C#

谢谢, 岜。

2 个答案:

答案 0 :(得分:10)

假设没有更改名称,这应该有效:

ThreadReceive = new System.Threading.Thread(receiveMessage);

AddressOf创建了ReceiveMessages的委托,这在C#中暗示。

答案 1 :(得分:1)

ThreadReceive = new System.Threading.Thread(ReceiveMessages);

其中ReceiveMessagesvoid类型的方法。