|
-
Feb 23rd, 2005, 08:57 AM
#1
Thread Starter
New Member
Binary streams in c#, please help [RESOLVED]
Hi,
I've got a weird problem with a while loop in c#. It seems like it's behaving like an IF statement
I have this code:
Code:
Byte[] bytesRead = new Byte[10];
while((intBytes = myTcpClientStream.Read(bytesRead, 0, bytesRead.Length)) > 0){
binaryWriter.Write(bytesRead, 0, intBytes);
bytesRead = new Byte[10];
}
//etc.
The total amount of bytes being written here, is 51. It repeats 6 times, which is good. But then it gots stuck or something at the while statement. It never reaches the statements after the loop.
I tried to change the number of bytes that will be read to 51 or even to 1, but no luck. For some reason, the code doesn't know what to do if the evaluation for the loop is false.
Strangely, this works well:
Code:
Byte[] bytesRead = new Byte[51];
intBytes = myTcpClientStream.Read(bytesRead, 0, bytesRead.Length);
binaryWriter.Write(bytesRead, 0, intBytes);
// etc.
But, obviously, this last code isn't very generic...
So, now I got stuck here. Any suggestions are welcome! Maybe I did something wrong with the syntax? Simple while loops (like: while(x == true){ x = false; }) do work fine.
I'm using .NET Framework 1.1, VS.NET 2003, C# 1.1
Last edited by Lucas82; Feb 26th, 2005 at 05:52 PM.
Reason: resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|