/// <summary>Copies a specified number of bytes from a source array starting at a particular offset to a destination array starting at a particular offset.</summary> /// <param name="src">The source buffer. </param> /// <param name="srcOffset">The zero-based byte offset into <paramref name="src" />. </param> /// <param name="dst">The destination buffer. </param> /// <param name="dstOffset">The zero-based byte offset into <paramref name="dst" />. </param> /// <param name="count">The number of bytes to copy. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="src" /> or <paramref name="dst" /> is null. </exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="src" /> or <paramref name="dst" /> is not an array of primitives.-or- The length of <paramref name="src" /> is less than <paramref name="srcOffset" /> plus <paramref name="count" />.-or- The length of <paramref name="dst" /> is less than <paramref name="dstOffset" /> plus <paramref name="count" />. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="srcOffset" />, <paramref name="dstOffset" />, or <paramref name="count" /> is less than 0. </exception> /// <filterpriority>1</filterpriority> public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) { throw new ArgumentNullException("src"); } if (dst == null) { throw new ArgumentNullException("dst"); } if (srcOffset < 0) { throw new ArgumentOutOfRangeException("srcOffset", Locale.GetText("Non-negative number required.")); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException("dstOffset", Locale.GetText("Non-negative number required.")); } if (count < 0) { throw new ArgumentOutOfRangeException("count", Locale.GetText("Non-negative number required.")); } if (!Buffer.BlockCopyInternal(src, srcOffset, dst, dstOffset, count) && (srcOffset > Buffer.ByteLength(src) - count || dstOffset > Buffer.ByteLength(dst) - count)) { throw new ArgumentException(Locale.GetText("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.")); } }
byte [] GetStringBytes(byte [] buffer, int offset) { int length = 0; int off = offset; while (buffer [off++] != 0) { length++; } byte [] result = new byte [length]; Buffer.BlockCopyInternal(buffer, offset, result, 0, length); return(result); }