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

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;
    }
}
    原文作者:艾孜尔江
    原文地址: https://blog.csdn.net/weixin_43867242/article/details/104268091
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞