Is there a less painful way to GetBytes for a buffer not starting at 0?
Posted
by Earlz
on Stack Overflow
See other posts from Stack Overflow
or by Earlz
Published on 2010-03-26T21:56:54Z
Indexed on
2010/03/26
22:03 UTC
Read the original article
Hit count: 336
I am having to deal with raw bites in a project and I need to basically do something like this
byte[] ToBytes(){
byte[] buffer=new byte[somelength];
byte[] tmp=new byte[2];
tmp=BitConverter.GetBytes(SomeShort);
buffer[0]=tmp[0];
buffer[1]=tmp[1];
tmp=BitConverter.GetBytes(SomeOtherShort);
buffer[2]=tmp[0];
buffer[3]=tmp[1];
}
I feel like this is so wrong yet I can't find any better way of doing it. Is there an easier way?
© Stack Overflow or respective owner