C# 基础—— 数组拼接[字节拼接]

方法1 Concat函数

这个方法方便一些

var byte_正文长度字节 = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((int) _msgSend_发送的信息.Length));
var byte_正文字节 = Encoding.UTF8.GetBytes(_msgSend_发送的信息);
var bytes_待发送的字节 = byte_正文长度字节.Concat(byte_正文字节).ToArray();

方法2 Array.Copy

网上的介绍的多为这个,用起来很麻烦

byte[] bytes_待发送的字节1 = new byte[byte_正文长度字节.Length + byte_正文字节.Length];
Array.Copy(byte_正文长度字节, 0, bytes_待发送的字节, 0, byte_正文长度字节.Length);
Array.Copy(byte_正文字节, 0, bytes_待发送的字节, byte_正文长度字节.Length, byte_正文字节.Length);

猜你喜欢

转载自blog.csdn.net/scy261983626/article/details/120386746