如何将以下代码行从VB.NET转换为C#。将这行代码从VB.NET转换为C#?
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
我从developerfusion网站下了一行,但它在我的程序中给了我错误的结果。
byte[] bytes = new byte[tcpClient.ReceiveBufferSize + 1];
这是我在Visual Basic中完整代码的一个示例。
Dim tcpClient As New System.Net.Sockets.TcpClient()
TcpClient.Connect(txtIP.Text, txtPort.Text)
Dim networkStream As NetworkStream = TcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(txtSend.Text.Trim())
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
TcpClient.ReceiveBufferSize = 52428800 '50 MB
'Do I need to clean the buffer?
'Get the string back (response)
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
谷歌当然! http://converter.telerik.com/ – 2012-04-02 14:04:22
为什么你在缓冲区大小声明中加1? – Oded 2012-04-02 14:04:42
该代码错误。我该如何翻译此代码昏暗的字节(tcpClient.ReceiveBufferSize)作为字节 – user67144 2012-04-02 14:06:55