旗下导航:搜·么
当前位置:网站首页 > .Net教程 > 正文

C#二进制字节数组操纵函数 截取字节数组SubByte的示例代码【C#.Net教程】,C#,二进制,SubByte

作者:搜教程发布时间:2019-11-27分类:.Net教程浏览:69评论:0


导读:C#二进制字节数组操纵函数截取字节数组SubByte///<summary>///截取字节数组//...
C#二进制字节数组操纵函数 截取字节数组SubByte

        /// <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的示例代码的细致内容,更多请关注ki4网别的相干文章!

标签:C#二进制SubByte


欢迎 发表评论: