user3075085
user3075085

Reputation: 103

C# equivalent of VB.Net AddressOf Operator

Code:

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

Can anyone Please Suggest me How to convert this line:

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

vb to C#

Thanks, Basha.

Upvotes: 8

Views: 23622

Answers (2)

Austin Salonen
Austin Salonen

Reputation: 50225

Assuming no name changes, this should work:

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

AddressOf creates a delegate to ReceiveMessages and this is implied in C#.

Upvotes: 15

Kai Hartmann
Kai Hartmann

Reputation: 3154

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

where ReceiveMessages is a method of type void.

Upvotes: 1

Related Questions