System.Runtime.InteropServices.Marshal.ReadByte Method

Reads a single byte at a given offset (or index) from unmanaged memory.

Syntax

[System.Security.SuppressUnmanagedCodeSecurity]
public static byte ReadByte (object ptr, int ofs)

Parameters

ptr
The base address in unmanaged memory of the source object.
ofs
An additional byte offset, which is added to the ptr parameter before reading.

Returns

The byte read from unmanaged memory at the given offset.

Remarks

Marshal.ReadByte(object, int) enables direct interaction with an unmanaged C-style byte array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy(Int32[], int, IntPtr, int)) to a separate managed array before reading its element values.

Reading from unaligned memory locations is supported.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0