memcpy like operation..

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

e.g.
byte[] z = new byte[255];
int a = 10;
int b= 20;

I wanna do sth like

memcpy(&z[10], &a, sizeof(a));

how can I do it in c#?
do I need to do things like

byte[] temp = System.BitConverter.GetBytes(a);
for (int i=0;i<temp.Length;i++
z[10+i] = temp;

thx....
 
Hi,

This seems to be the .NET way of doing it as you embed no knowledge of how
an integer is actually represented by a sequence of bytes into your code -
the BitConverter class does this for you and should this change in the next
version of the framework, you're on the safe side.
 
e.g.
byte[] z = new byte[255];
int a = 10;
int b= 20;

I wanna do sth like

memcpy(&z[10], &a, sizeof(a));

System.BitConverter.GetBytes(a).CopyTo(z,10);

Till Meyer
 
Back
Top