Let's say I have the following variables:
byte[] fileData;
List<byte> bundleData;
and I'd like to take a contiguous portion of fileData and add it to bundleData. My current method is essentially the following:
int startIndex = 20, endIndex = 80;
byte[] transferredData = new byte[endIndex - startIndex];
Array.Copy(fileData, startIndex, transferredData, 0, transferredData.Length);
bundleData.AddRange(transferredData);
Creating the intermediate array works fine, but it uses what seems like an unnecessary copy. Is there any way to add the data directly, without the use of a redundant array?
For reference, I'm using .NET 2.0 on this project.
AddRangethat adds only a portion of a collection, so I hoped for an equivalent somewhere.