George
George

Reputation: 407

I want to move 1 array to another in C#

This is just a quick question in C#.

I have a scenario where I am working with several devices that all have slightly different data to work with.

When I work out which device I am using, I want to set up a common array to use throughout the code, say arrayCommon.

So I want to move the info from device1 to the common array.

Do I have to do this in a loop for each occurance in the array or can u move the whole array into the common array, as you could in Cobol all those years ago ?

Thanks, George.

Upvotes: 1

Views: 389

Answers (3)

Kyle Rosendo
Kyle Rosendo

Reputation: 25277

Just a note, if you are needing it in a performance critical section of code, rather use:

Buffer.BlockCopy()

Link here.

Upvotes: 2

identy
identy

Reputation: 237

 Array array = new char["String".Length];
 "String".ToCharArray().CopyTo(array, 0);

Upvotes: 1

Ahmet Kakıcı
Ahmet Kakıcı

Reputation: 6404

I think you are looking for that : Array.Copy

Upvotes: 8

Related Questions