I have this.
This is a small part of a larger Class.
What the intent is, is to request a specific quantity of bytes from a networkstream and return it as a byte array.
If for some reason this fails (ie underlying socket is closed ), I return nothing.
Obviously I would check what was returned before processing the result.
I have read that I should not return nothing, so any suggestions on a better approach?
Code:
Private Function GetXAmountBytes(ByVal amount As Integer) As Byte()
Dim buffer(amount - 1) As Byte
Dim BytesRead As Integer = 0
Dim offset As Integer = 0
Dim newByteCount As Integer = 0
Try
Do
newByteCount = clientStream.Read(buffer, offset, amount - BytesRead)
If newByteCount <> 0 Then
BytesRead += newByteCount
offset = BytesRead
Else
buffer = Nothing
Exit Do
End If
Loop While BytesRead <> amount
Catch ex As Exception
buffer = Nothing
End Try
Return buffer
End Function
What the intent is, is to request a specific quantity of bytes from a networkstream and return it as a byte array.
If for some reason this fails (ie underlying socket is closed ), I return nothing.
Obviously I would check what was returned before processing the result.
I have read that I should not return nothing, so any suggestions on a better approach?