memcpy function in c# [duplicate]

Possible Duplicate:
C# memcpy equivalent

What is the equivalent of the memcpy function in c#?


Solution 1:

As already said it depends what you are trying to do... So you can consider one of these... check the links:

  • Array.Copy
  • Object.MemberwiseClone
  • ICloneable Interface

There may be other possible options based on your needs...

Solution 2:

Buffer.BlockCopy is close, but limited to arrays. I agree it depends what you're trying to do.

Solution 3:

For copying (byte) arrays, you can use the Array.Copy() method, but that's probably not what you want:

byte[] array1 = new byte[10] { 1,2,3,4,5,6,7,8,9,10 };
byte[] array2 = new byte[10];

Array.Copy(array1,array2,10);

Solution 4:

There is none. C# protects the actual memory behind several layers of abstraction. For some purposes, the IClonable interface may be of some help though.

Solution 5:

Not an exact equivalent, but does Array::Copy do what you need to do?