C# 等效于 VB.Net AddressOf 运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20428321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:03:19  来源:igfitidea点击:

C# equivalent of VB.Net AddressOf Operator

c#vb.net

提问by user3075085

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#

VB 到 C#

Thanks, Basha.

谢谢,巴沙。

回答by Austin Salonen

Assuming no name changes, this should work:

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

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

AddressOfcreates a delegate to ReceiveMessagesand this is implied in C#.

AddressOf创建一个委托给ReceiveMessages,这在 C# 中是隐含的。

回答by Kai Hartmann

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

where ReceiveMessagesis a method of type void.

哪里ReceiveMessages是类型的方法void