Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Getting a subarray

Started by BradDaBug Aug 14, 2006 at 6:38 PM 1 replies 6.1k views
Original Post
BradDaBug
BradDaBug
Let's say I've got an array, and I want to use a smaller part of that array. In C I could do this:
blah* subarray = &bigarray[10];
and then subarray would be an array that starts at the 10th element of bigarray. Best of all, I don't have to make a copy of an array. How would I do that in C#? It doesn't even look like I can use Array.CopyTo() since the index it takes is the destination start index, not the start index of the source array. Is the only way to do it with a for-loop?

blah[] subarray = new blah[bigarray.Length - 5];
for (int i = 0; i < bigarray.Length - 5; i++)
{
   subarray = bigarray[5 + i];
}
I like the DARK layout!
BradDaBug
BradDaBug
Oh cripes, why didn't I see that method earlier? Thanks!
I like the DARK layout!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.