|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Array subset copyingIf I have an array..
object[] myObjs = someMethod.SearchForObjs(); and the length of that array is 100, but I want to extract the last 80 objects into another array, what's the cleanest way to do that? Array.CopyTo seems to allow specification of target index to start copying into, but not the source array index. Do I need to brute force it and go with a for loop? Thanks in advance! Derrick Derrick the Array.Copy function should work for you.
[C#] public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length); Show quote "Derrick" wrote: > If I have an array.. > > object[] myObjs = someMethod.SearchForObjs(); > > and the length of that array is 100, but I want to extract the last 80 > objects into another array, what's the cleanest way to do that? > Array.CopyTo seems to allow specification of target index to start copying > into, but not the source array index. Do I need to brute force it and go > with a for loop? > > Thanks in advance! > > Derrick > > > Take a look at the System.Buffer.BlockCopy method.
Peter Show quote "Derrick" <derrick1***@excite.com> wrote in message news:uvOA2iUMFHA.2252@TK2MSFTNGP15.phx.gbl... > If I have an array.. > > object[] myObjs = someMethod.SearchForObjs(); > > and the length of that array is 100, but I want to extract the last 80 > objects into another array, what's the cleanest way to do that? > Array.CopyTo seems to allow specification of target index to start copying > into, but not the source array index. Do I need to brute force it and go > with a for loop? > > Thanks in advance! > > Derrick > > |
|||||||||||||||||||||||