See Also: Buffer Members
C# Example
int[] arr = new int[10];
C# Example
using System;
using System.Text;
public class BufferTest {
public static void Main (string[] args)
{
int[] arr1 = { 65, 66, 67, 68, 69, };
byte[] arr2 = new byte[16];
// prints "arr1 length in bytes is 20" (5 * 4)
Console.WriteLine ("arr1 length in bytes is {0}",
Buffer.ByteLength (arr1));
Buffer.BlockCopy (arr1, 1, arr2, 0, 12);
// prints "BCD" (which is 66, 67, 68).
// The NUL inbetween bytes are skipped.
Console.WriteLine (Encoding.ASCII.GetString (arr2));
// note that the following is endian dependant
StringBuilder byteStr = new StringBuilder ();
for (int n = 0 ; n < Buffer.ByteLength (arr1) ; ++n) {
byte b = Buffer.GetByte (arr1, n);
byteStr.Append ("0123456789abcdef"[b >> 4]);
byteStr.Append ("0123456789abcdef"[b & 0xf]);
byteStr.Append (" ");
}
Console.WriteLine ("hexdump of arr1: {0}", byteStr);
}
}