两个byte数组拼接_c#如何将两个字节数组合并为一个新的字节数组呢?
摘要:下文通过c#将字节数组合并的方法说明,如下所示;实现思路:1.定义一个新的字节数组,其数组长度为两个数组之和2.使用数组的Array.Copy方法将字节数组分别复制到新的字节数组中例:将两个字节数组合并到一个新的字节数组using System;using System.Text;using System.Collections.Generic;namespace consoleTest{c
摘要:
下文通过c#将字节数组合并的方法说明,如下所示;
实现思路:
1.定义一个新的字节数组,
其数组长度为两个数组之和
2.使用数组的Array.Copy方法将字节数组分别复制到新的字节数组中
例:
将两个字节数组合并到一个新的字节数组
using System;
using System.Text;
using System.Collections.Generic;
namespace consoleTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("maomao365.com示例分享");
string s1 = "maomao365.com";
byte[] bytes1 = Encoding.UTF8.GetBytes(s1);
string s2 = "linux28.com";
byte[] bytes2 = Encoding.UTF8.GetBytes(s2);
/*合并字节数组的方法*/
byte[] byteAll = new byte[bytes1.Length + bytes2.Length];
Array.Copy(bytes1, 0, byteAll, 0, bytes1.Length);
Array.Copy(bytes2, 0, byteAll,bytes1.Length, bytes2.Length);
Console.WriteLine("合并后的字节数组");
Console.WriteLine(Encoding.UTF8.GetString(byteAll));
Console.ReadLine();
}
}
}
c#合并字节数组的示例分享
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)