C#合并三个字节数组的方式_艾孜尔江撰

余生长醉 提交于 2020-02-13 10:55:30
public static byte[] addBytes(byte[] data1, byte[] data2, byte[] data3)
{
    if (data1.Length.Equals(0) || data2.Length.Equals(0))
    {
        if (data3.Length.Equals(0))
        {
            if (data1.Length.Equals(0))
            {
                return data2;
            }
            else
            {
                return data1;
            }
        }
        else
        {
            if (data1.Length.Equals(0))
            {
                byte[] result = new byte[data2.Length + data3.Length];
                Buffer.BlockCopy(data2, 0, result, 0, data2.Length);
                Buffer.BlockCopy(data3, 0, result, data2.Length, data3.Length);
                return result;
            }
            else
            {
                byte[] result = new byte[data1.Length + data3.Length];
                Buffer.BlockCopy(data1, 0, result, 0, data1.Length);
                Buffer.BlockCopy(data3, 0, result, data1.Length, data3.Length);
                return result;
            }
        }
    }
    else if (data1.Length.Equals(0) && data2.Length.Equals(0))
    {
        return data3;
    }
    else
    {
        byte[] result = new byte[data1.Length + data2.Length + data3.Length];
        Buffer.BlockCopy(data1, 0, result, 0, data1.Length);
        Buffer.BlockCopy(data2, 0, result, data1.Length, data2.Length);
        Buffer.BlockCopy(data3, 0, result, data1.Length + data2.Length, data3.Length);
        return result;
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!