Home All Groups Group Topic Archive Search About
Author
25 Mar 2005 2:41 PM
Derrick
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

Author
25 Mar 2005 3:55 PM
Kurt
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
>
>
>
Author
26 Mar 2005 3:19 AM
Peter Bromberg [C# MVP]
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
>
>

AddThis Social Bookmark Button