C#分割字节数组获最尾部字节数组_艾孜尔江撰

 public byte[] GetMsgAtTail(int spieces, byte[] msg2Spilt)
        {
            int remainder = msg2Spilt.Length % spieces;
            byte[] result = new byte[(msg2Spilt.Length - remainder) / spieces];
            if (spieces.Equals(0))
            {
                return msg2Spilt;
            }
            else if (!remainder.Equals(0))
            {
                byte[] volumLeft = new byte[remainder * spieces];
                Buffer.BlockCopy(msg2Spilt, (msg2Spilt.Length - spieces * remainder), volumLeft, 0, volumLeft.Length);
                return volumLeft;
            }
            else
            {
                Buffer.BlockCopy(msg2Spilt, (msg2Spilt.Length - msg2Spilt.Length / spieces), result, 0, result.Length);
                return result;
            }
        }

将一个字节数组传入,方法会将字节数组分隔成指定的份数,返回最末尾那一份的字节数组。
——艾孜尔江撰。

发布了29 篇原创文章 · 获赞 32 · 访问量 4737

猜你喜欢

转载自blog.csdn.net/weixin_43867242/article/details/104273633