copy array to array

  • Thread starter Thread starter Jan
  • Start date Start date
J

Jan

hi there,

How can i copy the entire content of an array in to another array?
I think for a pro user of vb.net it must be a easy question but not for a
starter like me

Thank you very much
 
hi there,

How can i copy the entire content of an array in to another array?
I think for a pro user of vb.net it must be a easy question but not for a
starter like me

Thank you very much

Look at the System.Array.Copy method...

Tom Shelton
 
Jan said:
How can i copy the entire content of an array in to another array?

\\\
Dim astr1() As String = {"Hello", "World", "Bla"}
Dim astr2(astr1.Length - 1) As String
astr1.CopyTo(astr2, 0)
Dim s As String
For Each s In astr2
MsgBox(s)
Next s
///
 
I forgot to mention that you can use 'Array.Copy' for copying an array too.
 
Herfried,
You are right, I was looking at the for each loop and did not take time to
look well.
I was thinking you was copying it value by value.
:-)
Cor
 
Herfried,
Another alternative is System.Buffer.BlockCopy, especially if you are
dealing with Arrays of Primitive Types (Byte, Char, Short, Integer, Long,
Single, Double). Actually Buffer only works with arrays of Primitive Types.

Reading the help it sounds like Buffer performs better then the similar
methods in Array.

Hope this helps
Jay
 
Back
Top