By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,684 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,684 IT Pros & Developers. It's quick & easy.

copy array to array

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In article <1l******************************@40tude.net>, Jan wrote:
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
Nov 20 '05 #2

P: n/a
Jan <ca*****@planet.nl> scripsit:
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
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
I forgot to mention that you can use 'Array.Copy' for copying an array too.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
Cor
Hi Herfried,
I forgot to mention that you can use 'Array.Copy' for copying an array

too.
Is it better or "use too"?
:-))
Cor
Nov 20 '05 #5

P: n/a
* "Cor" <no*@non.com> scripsit:
I forgot to mention that you can use 'Array.Copy' for copying an array
too.


Is it better or "use too"?


It's an alternative.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
Cor
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
Nov 20 '05 #7

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de...
* "Cor" <no*@non.com> scripsit:
I forgot to mention that you can use 'Array.Copy' for copying an array
too.


Is it better or "use too"?


It's an alternative.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.