Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

System.Buffer

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).

Listing B.2. System.Buffer Sample
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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book