我有一个 C# 代码,它将字节从特定索引复制到字节数组,如下例所示:
string headerInfo = String.Format(source + "<>" + destination + "<>" + sessionId);
headerInfo = headerInfo.TrimEnd('\n', '\0', '\r');
byte[] headerInfoBytes = Encoding.UTF8.GetBytes(headerInfo);
byte[] headerInfoLength = BitConverter.GetBytes(headerInfo.Length);
//create an byte Array with proper size.
byte[] sendData = new byte[4 + 4 + headerInfoBytes.Length + dataContractBytes.Length];
headerInfoLength.CopyTo(sendData, 0);
dataContractLengthBytes.CopyTo(sendData, 4);
headerInfoBytes.CopyTo(sendData, 8);
dataContractBytes.CopyTo(sendData, 8 + headerInfoBytes.Length);
m_clientSocket.Send(sendData);
我的问题是,如何以客观 c 方式实现 CopyTo?