如何將以下代碼行從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