0

I have a 2 dimensional array.
Like,
(0,1)
(0,2)
(0,3)
(1,1)
(1,2)
(1,3)
(2,1)
(2,2)
(2,3)

How can i use Array.Copy to copy only the 2nd index in a new array.
Like only,
(2,1)
(2,2)
(2,3)

Or is there any other way.

user2322507
  • 141
  • 1
  • 5
  • 19
  • You could use a foreach construction.. but that is probably not realy effcient. – Bart Teunissen Aug 28 '13 at 09:40
  • @BartTeunissen not really efficient? There are not too many things more efficient than looping through simple arrays. There you have a link (in C# but instructive anyway): http://stackoverflow.com/questions/7483893/is-array-copy-faster-than-for-loop-for-2d-arrays – varocarbas Aug 28 '13 at 10:00
  • I understand that thats the case, but a foreach loop is more than one line of code, and i wasn't sure if there was an easier sollution.. that is what is was trying to say. – Bart Teunissen Aug 28 '13 at 10:02
  • @varocarbas...please suggest an answer...not able to conclude with the link – user2322507 Aug 28 '13 at 10:03
  • 1
    @BartTeunissen All clear. But some times, lines of code and efficiency are mixed up: a lower number of lines does not mean higher efficiency. A single line can call a really complex set of functions. For example, the "simple" arrays require more lines of code than "more complex" collection (e.g., List); but they are much more efficient as far as the complex collections need more resources to perform each single action. – varocarbas Aug 28 '13 at 10:05
  • I haven't written any answer because I only use Array.Copy with 1D arrays (otherwise, loops). I am not even sure about its exact applicability to 2D arrays (have read people talking about that, but never seen a working implementation). There are alternative approaches, but also never use them. Sorry but I am not in a position to answer this question (just to clarify the comment above). – varocarbas Aug 28 '13 at 10:07
  • And i haven't posted an anwser because i'm only into c# and not VB.net :) I have found a link though which you could use. http://stackoverflow.com/questions/2834233/how-to-foreach-through-a-2-dimensional-array – Bart Teunissen Aug 28 '13 at 10:15
  • I don't really understand which elements you want in your new array, it's difficult to understand from your example. Do you want a new array containing all the values from the second dimension of the array? – Erik A. Brandstadmoen Aug 28 '13 at 20:19

1 Answers1

0

Array.copy( source_array, 6, destin_array, )

Doug Null
  • 7,989
  • 15
  • 69
  • 148