title: Need loop to copy chunks from byte array
body: <p>I have to process a large byte array that is passed to my function. I need to copy the content from this incoming byte array in smaller "chunks" to an outbound byte array.</p>
  
  <p>For every "chunk" of data created in the outbound array, I need to call a web service.</p>
  
  <p>Upon return, I need to resume looping through the incoming byte array, continuing to pass a whole or partial chunk of data until the complete incoming array is processed (i.e. sent to the web service in chunks).</p>
  
  <p>I am very new to C# and I am struggling with a loop that works. I know how to call the web service to handle a "chunk" but I can't get the looping correct. Here is a sketch of the pathetic mess I currently have:</p>
  
  <pre><code>int chunkSize = 10000;
  byte[] outboundBuffer = new byte[chunkSize];     
  while (BytesRead &gt; 0)
  {
  long i = 0;
  foreach (byte x in incomingArray)
  {
      BytesRead += 1;
      outboundBuffer[i] = incomingArray[i]
      i++;
  }
  uploadObject.Size = BytesRead;
  uploadObject.MTOMPayload = outboundBuffer;
  
  // call web service here and pass the uploadObject 
  
  // get next "chunk" until incomingArray is fully processed 
   }
  </code></pre>
  
  <p>I know this is a mess and won't work; could someone sketch a proper loop to get this done? Thanks very much. </p>