April 2002
Intermediate to advanced
1024 pages
23h 26m
English
The Buffer class allows the programmer to perform simple manipulation of a managed type as if it were unmanaged. Essentially, the type of the data is ignored.
Listing B.2 shows an example of manipulating an integer array without respect to its type (buffer.cs).
public class BufferMain
{
static void Main(string [] args)
{
int [] rawData = new int [] {1,2,3,4} ;
Console.WriteLine("Array byte length: {0} ",
Buffer.ByteLength(rawData));
for(int i = 0;i < Buffer.ByteLength(rawData); i++)
{
if((i % 4) == 0)
Console.WriteLine();
Console.Write("0x{0:X} ", Buffer.GetByte(rawData, i));
}
}
}
|
This array contains 4 integers. Each integer requires 4 bytes of storage, so the array takes up 16 bytes. The output ...