/// <summary> /// 截取字节数组 /// </summary> /// <param name="srcBytes">要截取的字节数组</param> /// <param name="startIndex">开始截取位置的索引</param> /// <param name="length">要截取的字节长度</param> /// <returns>截取后的字节数组</returns> public byte[] SubByte(byte[] srcBytes, int startIndex, int length) { System.IO.MemoryStream bufferStream = new System.IO.MemoryStream(); byte[] returnByte = new byte[] { }; if (srcBytes == null) { return returnByte; } if (startIndex < 0) { startIndex = 0; } if (startIndex < srcBytes.Length) { if (length < 1 || length > srcBytes.Length - startIndex) { length = srcBytes.Length - startIndex; } bufferStream.Write(srcBytes, startIndex, length); returnByte = bufferStream.ToArray(); bufferStream.SetLength(0); bufferStream.Position = 0; } bufferStream.Close(); bufferStream.Dispose(); return returnByte; } }
以上就是C#二进制字节数组操作函数 截取字节数组SubByte的示例代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号