473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Array subset copying

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
Nov 17 '05 #1
3 10920
Derrick the Array.Copy function should work for you.

[C#]
public static void Copy(Array sourceArray, int sourceIndex, Array
destinationArray,
int destinationIndex, int length);

"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

Nov 17 '05 #2
Take a look at the System.Buffer.BlockCopy method.
Peter

"Derrick" <de*********@excite.com> wrote in message
news:uv**************@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

Nov 17 '05 #3
Take a look at the System.Buffer.BlockCopy method.
Peter

"Derrick" <de*********@excite.com> wrote in message
news:uv**************@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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Carson | last post by:
Hi , Is there a very efficient way to set a double array to 0 ? (I have tried memset, but the result doesn't look correct.) Carson
4
by: Sharon | last post by:
I’m using a one dimensional array: byte bArray = new byte; And I’m writing a function that return a subset of this array: void GetSubArray(int offset, int size, ref byte subArray); As you...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
6
by: ad | last post by:
I have a huge sting array, there are about 1000 element in it. How can I divide the huge array into small ones, and there are one 10 elements in a small one array?
6
by: Denis C | last post by:
Hi I have a byte array of length 2404. I want to access subsets of the array and pass the subset to the constructor of a class. i.e. Dim bData(2403) As Byte Dim aThing As SomeClass = new...
7
by: Jacob JKW | last post by:
I need to iterate over combinations of n array elements taken r at a time. Because the value of r may vary quite a bit between program invocations, I'd like to avoid simply hardcoding r loops. I...
1
by: RonLandreth | last post by:
I am writing an accounting system for a class I'm taking at SLU. I need help figuring out the best way to go about copying a 2D array to a temporary 2D array, for eventually copying it back. ...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.