I want to write a Method chain to add CRC ( 2 byte ) with byte[]. with internet source, I write this . but not work... with less knowledge,I do not know why... Please help me..
public byte[] AddCrc<T>(this byte[] x)
{
if (x == null) throw new ArgumentNullException("x");
int oldLen = x.Length;
byte[] y = makeCrc2bytes(x, oldLen);
Array.Resize<byte>(ref x, x.Length + y.Length);
Array.Copy(y, 0, x, oldLen, y.Length);
return x;
}
... Example ...
byte[] buffer = new byte[6];
buffer[0] = 0x01;
buffer[1] = 0x02;
buffer[2] = 0x03;
buffer[3] = 0x04;
buffer[4] = 0x05;
buffer[5] = 0x06;
byte[] buffer2 = buffer.AddCrc(); // Now work.