If I understand the question correctly, you want to chop the existing array into arrays of (at most) 100k elements, and put those arrays in the array list?
ArrayList Split(byte[] filebytes, int range)
{
range *= 1000;
int pos = 0;
int remaining;
ArrayList result = new ArrayList();
while ((remaining = filebytes.Length - pos) > 0)
{
byte[] block = new byte[Math.Min(remaining, range)];
Array.Copy(filebytes, pos, block, 0, block.Length);
result.Add(block);
pos += block.Length;
}
return result;
}
Change 1000 to 1024 if that was your intention :)
I can't really think of a reason why you'd want to do something like this though. Loading one huge array of bytes and then splitting into blocks is rather inefficient if you could have split them into 100k blocks while reading your data.
Regarding your comment: sending an entire file to a socket should be much simpler than you're making it to be. I have no way of testing, but this should work in .NET 1.1.
private void SendFileToSocket(string fileName)
{
Socket socket = new Socket(
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
using (socket)
{
socket.Connect("server.domain.com", 12345);
using (NetworkStream networkStream = new NetworkStream(socket))
using (FileStream fileStream = File.OpenRead(fileName))
{
byte[] buffer = new byte[32768];
while (true)
{
int bytesRead = fileStream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
networkStream.Write(buffer, 0, bytesRead);
}
}
}
}
The buffer size is a little arbitrary, but it should be large enough.