I am new to VB.net and struggling to get out of VB6's way of sending data, I am doing this to send a byte array from my client to server, please advice if this is the right way, thanks:
The sendi开发者_如何转开发ng portion:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim arrNo(3) As Integer
arrNo(0) = 1400
arrNo(1) = 1000
arrNo(2) = 1200
arrNo(3) = 1350
Dim i As Integer
For i = 0 To arrNo.Length - 1
Dim outStream() As Byte = BitConverter.GetBytes(arrNo(i))
Debug.Print(arrNo(i))
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Next
End Sub
In VB6, an Integer was 2 bytes. Use Short in VB.NET. Move the Flush out of the For loop. The rest looks okay.
In VB.NET you can declare the variable as part of the for loop syntax.
For i As Integer = 0 To arrNo.Length - 1
...
Next
You can also provide array initializers in the declaration (although that probably doesn't apply to your actual code so much as your sample code):
Dim arrNo As Integer() = {1400, 1000, 1200, 1350}
精彩评论