C # equivalent of VB.Net AddressOf statement

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 suggest me How to convert this line:

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

vb to c #

Thanks, Bash.

+6
source share
2 answers

Assuming the name doesn't change, this should work:

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

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

EDIT: based on the comments the name has changed:

 ThreadReceive = new System.Threading.Thread(receiveMessage); 
+10
source
 ThreadReceive = new System.Threading.Thread(ReceiveMessages); 

where ReceiveMessages is a method of type void .

+1
source

Source: https://habr.com/ru/post/959489/


All Articles